Skip to content

Commit 1de3bf0

Browse files
authored
perf: process js files in node_modules with esbuild (#1169)
BREAKING CHANGE `js` files from `node_modules` are now compiled with `esbuild` to improve performance
1 parent 3458936 commit 1de3bf0

23 files changed

+471
-60
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ e2e/**/.yarn/*
1818
!e2e/**/.yarn/sdks
1919
!e2e/**/.yarn/versions
2020
!/e2e/ng-lib-import/node_modules
21+
!/e2e/process-js-packages/node_modules
2122
src/transformers/downlevel_decorators_transform
2223
src/ngtsc

e2e/__tests__/ast-transformers.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { json as runWithJson } from '../run-jest';
1+
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';
22

33
describe('hoisting', () => {
44
const DIR = 'ast-transformers/hoisting';
55

66
test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
7-
const { json } = runWithJson(DIR);
7+
const { json } = runWithJsonNoCache(DIR);
88

99
expect(json.success).toBe(true);
1010
});
1111

1212
test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
13-
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
13+
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);
1414

1515
expect(json.success).toBe(true);
1616
});
@@ -20,13 +20,13 @@ describe('ng-jit-transformers', () => {
2020
const DIR = 'ast-transformers/ng-jit-transformers';
2121

2222
test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
23-
const { json } = runWithJson(DIR);
23+
const { json } = runWithJsonNoCache(DIR);
2424

2525
expect(json.success).toBe(true);
2626
});
2727

2828
test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
29-
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
29+
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);
3030

3131
expect(json.success).toBe(true);
3232
});

e2e/__tests__/async.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path';
22

3-
import { json as runWithJson } from '../run-jest';
3+
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';
44
import { runYarnInstall } from '../utils';
55

66
const DIR = path.join(__dirname, '..', 'async');
@@ -10,13 +10,13 @@ beforeAll(() => {
1010
});
1111

1212
test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
13-
const { json } = runWithJson(DIR);
13+
const { json } = runWithJsonNoCache(DIR);
1414

1515
expect(json.success).toBe(true);
1616
});
1717

1818
test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
19-
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
19+
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);
2020

2121
expect(json.success).toBe(true);
2222
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path';
22

3-
import { json as runWithJson } from '../run-jest';
3+
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';
44
import { runYarnInstall } from '../utils';
55

66
const DIR = path.join(__dirname, '..', 'babel-support');
@@ -10,13 +10,13 @@ beforeAll(() => {
1010
});
1111

1212
test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
13-
const { json } = runWithJson(DIR);
13+
const { json } = runWithJsonNoCache(DIR);
1414

1515
expect(json.success).toBe(true);
1616
});
1717

1818
test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
19-
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
19+
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);
2020

2121
expect(json.success).toBe(true);
2222
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path';
22

3-
import { json as runWithJson } from '../run-jest';
3+
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';
44
import { runYarnInstall } from '../utils';
55

66
const DIR = path.join(__dirname, '..', 'custom-typings');
@@ -10,13 +10,13 @@ beforeAll(() => {
1010
});
1111

1212
test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
13-
const { json } = runWithJson(DIR);
13+
const { json } = runWithJsonNoCache(DIR);
1414

1515
expect(json.success).toBe(true);
1616
});
1717

1818
test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
19-
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
19+
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);
2020

2121
expect(json.success).toBe(true);
2222
});

e2e/__tests__/jest-globals.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { json as runWithJson } from '../run-jest';
1+
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';
22

33
const DIR = 'jest-globals';
44

55
test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
6-
const { json } = runWithJson(DIR);
6+
const { json } = runWithJsonNoCache(DIR);
77

88
expect(json.success).toBe(true);
99
});
1010

1111
test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
12-
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
12+
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);
1313

1414
expect(json.success).toBe(true);
1515
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { json as runWithJson } from '../run-jest';
1+
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';
22

33
const DIR = 'ng-deep-import';
44

55
test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
6-
const { json } = runWithJson(DIR);
6+
const { json } = runWithJsonNoCache(DIR);
77

88
expect(json.success).toBe(true);
99
});
1010

1111
test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
12-
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
12+
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);
1313

1414
expect(json.success).toBe(true);
1515
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { json as runWithJson } from '../run-jest';
1+
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';
22

33
const DIR = 'ng-lib-import';
44

55
test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
6-
const { json } = runWithJson(DIR);
6+
const { json } = runWithJsonNoCache(DIR);
77

88
expect(json.success).toBe(true);
99
});
1010

1111
test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
12-
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
12+
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);
1313

1414
expect(json.success).toBe(true);
1515
});

e2e/__tests__/path-mapping.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { json as runWithJson } from '../run-jest';
1+
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';
22

33
const DIR = 'path-mapping';
44

55
test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => {
6-
const { json } = runWithJson(DIR);
6+
const { json } = runWithJsonNoCache(DIR);
77

88
expect(json.success).toBe(true);
99
});
1010

1111
test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => {
12-
const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']);
12+
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);
1313

1414
expect(json.success).toBe(true);
1515
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
4+
import { jsonNoCache as runWithJsonNoCache } from '../run-jest';
5+
6+
const TEST_DIR_NAME = 'process-js-packages';
7+
const TEST_DIR_PATH = path.join(__dirname, '..', TEST_DIR_NAME);
8+
const LOG_FILE_NAME = 'ng-jest.log';
9+
const LOG_FILE_PATH = path.join(TEST_DIR_PATH, LOG_FILE_NAME);
10+
11+
test(`successfully runs the tests inside ${TEST_DIR_NAME}`, () => {
12+
process.env.NG_JEST_LOG = LOG_FILE_NAME;
13+
14+
const { json } = runWithJsonNoCache(TEST_DIR_NAME);
15+
16+
expect(json.success).toBe(true);
17+
expect(fs.existsSync(LOG_FILE_PATH)).toBe(true);
18+
19+
const logFileContent = fs.readFileSync(LOG_FILE_PATH, 'utf-8');
20+
const logFileContentAsJson = JSON.parse(logFileContent);
21+
22+
expect(/node_modules\/(.*.m?js$)/.test(logFileContentAsJson.context.filePath.replace(/\\/g, '/'))).toBe(true);
23+
expect(logFileContentAsJson.message).toBe('process with esbuild');
24+
25+
delete process.env.NG_JEST_LOG;
26+
fs.unlinkSync(LOG_FILE_PATH);
27+
});

0 commit comments

Comments
 (0)