chore: enable ts-esm support by default (#12658)

This commit is contained in:
Pavel Feldman 2022-03-10 14:48:33 -08:00 committed by GitHub
parent cf643ff04c
commit 4d3d0e2bda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 15 deletions

View File

@ -238,9 +238,9 @@ async function launchDockerContainer(): Promise<() => Promise<void>> {
function restartWithExperimentalTsEsm(configFile: string | null): boolean {
if (!configFile)
return false;
if (!process.env.PW_EXPERIMENTAL_TS_ESM)
if (process.env.PW_DISABLE_TS_ESM)
return false;
if (process.env.PW_EXPERIMENTAL_TS_ESM_ON)
if (process.env.PW_TS_ESM_ON)
return false;
if (!configFile.endsWith('.ts'))
return false;
@ -251,7 +251,7 @@ function restartWithExperimentalTsEsm(configFile: string | null): boolean {
env: {
...process.env,
NODE_OPTIONS,
PW_EXPERIMENTAL_TS_ESM_ON: '1',
PW_TS_ESM_ON: '1',
}
});

View File

@ -54,10 +54,10 @@ sourceMapSupport.install({
}
});
function calculateCachePath(content: string, filePath: string): string {
function calculateCachePath(content: string, filePath: string, isModule: boolean): string {
const hash = crypto.createHash('sha1')
.update(process.env.PW_TEST_SOURCE_TRANSFORM || '')
.update(process.env.PW_EXPERIMENTAL_TS_ESM ? 'esm' : 'no_esm')
.update(isModule ? 'esm' : 'no_esm')
.update(content)
.update(filePath)
.update(String(version))
@ -134,7 +134,7 @@ export function transformHook(code: string, filename: string, isModule = false):
if (!isTypeScript && !hasPreprocessor)
return code;
const cachePath = calculateCachePath(code, filename);
const cachePath = calculateCachePath(code, filename, isModule);
const codePath = cachePath + '.js';
const sourceMapPath = cachePath + '.map';
sourceMaps.set(filename, sourceMapPath);

View File

@ -260,9 +260,7 @@ test('should import esm from ts when package.json has type module in experimenta
'b.ts': `
export const foo: string = 'foo';
`
}, {}, {
PW_EXPERIMENTAL_TS_ESM: true
});
}, {});
expect(result.exitCode).toBe(0);
});
@ -278,9 +276,7 @@ test('should propagate subprocess exit code in experimental mode @esm', async ({
expect(1).toBe(2);
});
`,
}, {}, {
PW_EXPERIMENTAL_TS_ESM: true
});
}, {});
expect(result.exitCode).toBe(1);
});

View File

@ -195,9 +195,7 @@ test('should respect path resolver in experimental mode @esm', async ({ runInlin
'foo/bar/util/b.ts': `
export const foo: string = 'foo';
`,
}, {}, {
PW_EXPERIMENTAL_TS_ESM: true
});
}, {});
expect(result.exitCode).toBe(0);
});