Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
COMMIT TO DROP!!! (debugging)
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz committed Sep 23, 2024
1 parent 0d4ae34 commit ddc8615
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 75 deletions.
35 changes: 34 additions & 1 deletion .github/workflows/module-resolution-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,37 @@ jobs:

- name: Run tests
shell: bash
run: pnpm --filter cloudflare-dev-module-resolution-fixture test
run: DEBUG_DUMPS=true pnpm --filter cloudflare-dev-module-resolution-fixture test

- name: Log
if: always()
shell: bash
run: ls ./fixtures/cloudflare-dev-module-resolution/.workerd-env-dumps

- name: Upload all debug dumps
uses: actions/upload-artifact@v4
if: always()
with:
name: debug-dumps-00-${{matrix.os}}
path: ./fixtures/cloudflare-dev-module-resolution/.workerd-env-dumps/**/*

- name: Upload debug dumps 0
uses: actions/upload-artifact@v4
if: always()
with:
name: debug-dumps-00-${{matrix.os}}
path: ./fixtures/cloudflare-dev-module-resolution/.workerd-env-dumps/dev_run_00

- name: Upload debug dumps 1
uses: actions/upload-artifact@v4
if: always()
with:
name: debug-dumps-01-${{matrix.os}}
path: ./fixtures/cloudflare-dev-module-resolution/.workerd-env-dumps/dev_run_01

- name: Upload debug dumps 2
uses: actions/upload-artifact@v4
if: always()
with:
name: debug-dumps-02-${{matrix.os}}
path: ./fixtures/cloudflare-dev-module-resolution/.workerd-env-dumps/dev_run_02
33 changes: 0 additions & 33 deletions fixtures/cloudflare-dev-module-resolution/index.test.ts

This file was deleted.

30 changes: 0 additions & 30 deletions fixtures/cloudflare-dev-module-resolution/third-party.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,6 @@ import { fetchOutputFromViteDevServer } from './utils';
* special meaning to us.
*/
describe('third party packages resolutions', () => {
test('react', async () => {
const output = await fetchOutputFromViteDevServer('/third-party/react');

expect(output).toEqual({
'(react) reactVersionsMatch': true,
'(react) typeof React': 'object',
'(react) typeof React.cloneElement': 'function',
});
});

test('@remix-run/cloudflare', async () => {
const output = await fetchOutputFromViteDevServer('/third-party/remix');

expect(output).toEqual({
'(remix) remixRunCloudflareCookieName': 'my-remix-run-cloudflare-cookie',
'(remix) typeof cloudflare json({})': 'object',
});
});

test('discord-api-types/v10', async () => {
const output = await fetchOutputFromViteDevServer(
'/third-party/discord-api-types',
);

expect(output).toEqual({
'(discord-api-types/v10) RPCErrorCodes.InvalidUser': 4010,
'(discord-api-types/v10) Utils.isLinkButton({})': false,
});
});

test('slash-create', async () => {
const output = await fetchOutputFromViteDevServer(
'/third-party/slash-create',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,5 @@ let idx = 0;
export async function rawLog(toLog: unknown) {
if (!debugDumpsEnabled) return;

const separator = new Array(3)
.fill(null)
.map(() => '='.repeat(50))
.join('\n');

await appendFile(
__rawLogsFilePath,
`\n__rawLog(${idx++})\n${separator}\n${toLog}\n${separator}\n`,
);
await appendFile(__rawLogsFilePath, `\n__rawLog(${idx++})\n${toLog}\n`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const runName = `dev_run_${runNumber}`;
export const runDir = `${runsDir}/${runName}`;
const allImportsFilePath = `${runDir}/all-imports.txt`;

export const debugDumpsEnabled = !!process.env['DEBUG_DUMPS'];
export const debugDumpsEnabled = true; //!!process.env['DEBUG_DUMPS'];

if (debugDumpsEnabled) {
await mkdir(runDir, { recursive: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Request, Response } from 'miniflare';
import { collectModuleInfo } from './moduleUtils';
import { readFile, stat } from 'node:fs/promises';
import { URL } from 'url';
import { rawLog } from './debug-dumps';

export type ResolveIdFunction = (
id: string,
Expand All @@ -14,12 +15,21 @@ export type ResolveIdFunction = (
},
) => Promise<string>;

let idx = -1;
export function getModuleFallbackCallback(resolveId: ResolveIdFunction) {
return patchModuleFallbackHandler(
async (request: Request): Promise<Response> => {
const { resolveMethod, referrer, specifier, rawSpecifier } =
extractModuleFallbackValues(request);

idx++;
await rawLog(
`[mfs${idx}] module fallback service ==================================`,
);
await rawLog(`[mfs${idx}] referrer = ${referrer}`);
await rawLog(`[mfs${idx}] specifier = ${specifier}`);
await rawLog(`[mfs${idx}] rawSpecifier = ${rawSpecifier}`);

const referrerDir = dirname(referrer);

let fixedSpecifier = specifier;
Expand Down Expand Up @@ -49,6 +59,8 @@ export function getModuleFallbackCallback(resolveId: ResolveIdFunction) {
if (resolvedId.includes('?'))
resolvedId = resolvedId.slice(0, resolvedId.lastIndexOf('?'));

await rawLog(`[mfs${idx}] resolvedId = ${resolvedId}`);

const redirectTo =
!rawSpecifier.startsWith('./') &&
!rawSpecifier.startsWith('../') &&
Expand All @@ -58,6 +70,8 @@ export function getModuleFallbackCallback(resolveId: ResolveIdFunction) {
: undefined;

if (redirectTo) {
await rawLog(`[mfs${idx}] redirecting to ✈️ ${redirectTo}`);

return new Response(null, {
headers: { location: redirectTo },
status: 301,
Expand Down Expand Up @@ -246,7 +260,7 @@ function patchModuleFallbackHandler(
// https://github.com/cloudflare/workerd/blob/93953a/src/workerd/server/server.c%2B%2B#L2917-L2918
// the location returned to the module fallback service becomes the specifier that is then sent back to the module fallback
// service handler, which workerd expects to have a leading `/`
const fixedLocation = `${process.platform === 'win32' ? '/' : ''}${location}`;
const fixedLocation = location; // `${process.platform === 'win32' ? '/' : ''}${location}`;
return new Response(null, {
headers: { location: fixedLocation },
status: 301,
Expand Down

0 comments on commit ddc8615

Please sign in to comment.