@modern-js/babel-compiler 1.1.3-rc.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,17 +1,35 @@
1
1
  # @modern-js/babel-compiler
2
2
 
3
- ## 1.1.3-rc.0
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - cfe11628: Make Modern.js self bootstraping
8
+
9
+ ### Patch Changes
10
+
11
+ - 146dcd85: fix test case in babel compiler
12
+ - 1ebc7ee2: fix: @babel/core version
13
+ - Updated dependencies [2da09c69]
14
+ - Updated dependencies [c3d46ee4]
15
+ - Updated dependencies [cfe11628]
16
+ - @modern-js/utils@1.2.0
17
+
18
+ ## 1.1.4
19
+
20
+ ### Patch Changes
21
+
22
+ - 2da27d3b: fix sourcemap 'source' config
23
+ - Updated dependencies [b7fb82ec]
24
+ - @modern-js/utils@1.1.6
25
+
26
+ ## 1.1.3
4
27
 
5
28
  ### Patch Changes
6
29
 
7
- - Updated dependencies [d927bc83]
8
- - Updated dependencies [d73ff455]
9
- - Updated dependencies [9c1ab865]
10
- - Updated dependencies [d73ff455]
11
- - Updated dependencies [d73ff455]
12
- - Updated dependencies [d73ff455]
13
- - Updated dependencies [d73ff455]
14
- - @modern-js/utils@1.1.4-rc.0
30
+ - ca7dcb32: change watch logic
31
+ - Updated dependencies [ca7dcb32]
32
+ - @modern-js/utils@1.1.5
15
33
 
16
34
  ## 1.1.2
17
35
 
@@ -54,7 +54,7 @@ export const runBuildWatch = async (option, babelConfig = {}, emitter) => {
54
54
  emitter.emit(BuildWatchEvent.firstCompiler, fisrtBuildResult);
55
55
  }
56
56
 
57
- return watch(watchDir, async ({
57
+ return watch(`${watchDir}/**/*.{js,jsx,ts,tsx}`, async ({
58
58
  changeType,
59
59
  changedFilePath
60
60
  }) => {
@@ -24,6 +24,7 @@ export const getDistFilePath = option => {
24
24
  export const resolveSourceMap = option => {
25
25
  const {
26
26
  babelRes,
27
+ sourceFilePath,
27
28
  distFilePath,
28
29
  enableVirtualDist = false
29
30
  } = option;
@@ -32,6 +33,7 @@ export const resolveSourceMap = option => {
32
33
 
33
34
  if (babelRes.map) {
34
35
  babelRes.map.file = path.basename(distFilePath);
36
+ babelRes.map.sources = [path.relative(path.dirname(distFilePath), sourceFilePath)];
35
37
  }
36
38
 
37
39
  const sourceMapVirtualDist = {
@@ -85,12 +87,14 @@ export const compiler = option => {
85
87
  if (virtualDist) {
86
88
  virtualDist = _objectSpread(_objectSpread({}, virtualDist), resolveSourceMap({
87
89
  babelRes,
90
+ sourceFilePath: filepath,
88
91
  distFilePath,
89
92
  enableVirtualDist
90
93
  }));
91
94
  } else {
92
95
  resolveSourceMap({
93
96
  babelRes,
97
+ sourceFilePath: filepath,
94
98
  distFilePath,
95
99
  enableVirtualDist
96
100
  });
@@ -75,7 +75,7 @@ const runBuildWatch = async (option, babelConfig = {}, emitter) => {
75
75
  emitter.emit(BuildWatchEvent.firstCompiler, fisrtBuildResult);
76
76
  }
77
77
 
78
- return (0, _utils.watch)(watchDir, async ({
78
+ return (0, _utils.watch)(`${watchDir}/**/*.{js,jsx,ts,tsx}`, async ({
79
79
  changeType,
80
80
  changedFilePath
81
81
  }) => {
@@ -47,6 +47,7 @@ exports.getDistFilePath = getDistFilePath;
47
47
  const resolveSourceMap = option => {
48
48
  const {
49
49
  babelRes,
50
+ sourceFilePath,
50
51
  distFilePath,
51
52
  enableVirtualDist = false
52
53
  } = option;
@@ -55,6 +56,7 @@ const resolveSourceMap = option => {
55
56
 
56
57
  if (babelRes.map) {
57
58
  babelRes.map.file = path.basename(distFilePath);
59
+ babelRes.map.sources = [path.relative(path.dirname(distFilePath), sourceFilePath)];
58
60
  }
59
61
 
60
62
  const sourceMapVirtualDist = {
@@ -113,12 +115,14 @@ const compiler = option => {
113
115
  if (virtualDist) {
114
116
  virtualDist = _objectSpread(_objectSpread({}, virtualDist), resolveSourceMap({
115
117
  babelRes,
118
+ sourceFilePath: filepath,
116
119
  distFilePath,
117
120
  enableVirtualDist
118
121
  }));
119
122
  } else {
120
123
  resolveSourceMap({
121
124
  babelRes,
125
+ sourceFilePath: filepath,
122
126
  distFilePath,
123
127
  enableVirtualDist
124
128
  });
@@ -19,6 +19,7 @@ export declare const getDistFilePath: (option: {
19
19
  }) => string;
20
20
  export declare const resolveSourceMap: (option: {
21
21
  babelRes: babel.BabelFileResult;
22
+ sourceFilePath: string;
22
23
  distFilePath: string;
23
24
  enableVirtualDist?: boolean;
24
25
  }) => {
@@ -1,7 +1,7 @@
1
1
  import type { IOptions } from 'glob';
2
2
  import { Extensions, ExtensionsFunc, ICompilerOptions, IFinaleCompilerOptions } from './type';
3
3
  export declare const getGlobPattern: (dir: string, extensions: Extensions) => string;
4
- export declare const getFinalExtensions: (extensions: Extensions | ExtensionsFunc | undefined) => Extensions;
4
+ export declare const getFinalExtensions: (extensions: Extensions | ExtensionsFunc | undefined) => string[];
5
5
  export declare const getFilesFromDir: ({
6
6
  dir,
7
7
  finalExt,
package/jest.config.js ADDED
@@ -0,0 +1,8 @@
1
+ const sharedConfig = require('@scripts/jest-config');
2
+
3
+ /** @type {import('@jest/types').Config.InitialOptions} */
4
+ module.exports = {
5
+ // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
+ ...sharedConfig,
7
+ rootDir: __dirname,
8
+ };
package/modern.config.js CHANGED
@@ -4,16 +4,4 @@ module.exports = {
4
4
  // enableTsChecker: true,
5
5
  disableSourceMap: true,
6
6
  },
7
- testing: {
8
- jest: {
9
- // Reasons for setting up testRunner:
10
- // https://github.com/facebook/jest/issues/10529
11
- // https://jestjs.io/blog/2020/05/05/jest-26
12
- testRunner: 'jest-jasmine2',
13
- testEnvironment: 'node',
14
- collectCoverage: true,
15
- collectCoverageFrom: ['./src/**/*.ts'],
16
- coveragePathIgnorePatterns: ['/node_modules/', '/tests'],
17
- },
18
- },
19
7
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.3-rc.0",
14
+ "version": "1.2.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -20,6 +20,7 @@
20
20
  "exports": {
21
21
  ".": {
22
22
  "node": {
23
+ "jsnext:source": "./src/index.ts",
23
24
  "import": "./dist/js/modern/index.js",
24
25
  "require": "./dist/js/node/index.js"
25
26
  },
@@ -27,9 +28,9 @@
27
28
  }
28
29
  },
29
30
  "dependencies": {
30
- "@babel/core": "^7.15.0",
31
+ "@babel/core": "7.16.7",
31
32
  "@babel/runtime": "^7",
32
- "@modern-js/utils": "^1.1.4-rc.0",
33
+ "@modern-js/utils": "^1.2.0",
33
34
  "chokidar": "^3.5.2",
34
35
  "glob": "^7.1.6"
35
36
  },
@@ -42,8 +43,9 @@
42
43
  "@types/node": "^14",
43
44
  "jest-jasmine2": "^27.2.2",
44
45
  "typescript": "^4",
45
- "@modern-js/plugin-testing": "^1.1.1",
46
- "@modern-js/module-tools": "^1.1.1"
46
+ "@scripts/build": "0.0.0",
47
+ "jest": "^27",
48
+ "@scripts/jest-config": "0.0.0"
47
49
  },
48
50
  "sideEffects": false,
49
51
  "modernConfig": {
@@ -53,12 +55,13 @@
53
55
  },
54
56
  "publishConfig": {
55
57
  "registry": "https://registry.npmjs.org/",
56
- "access": "public"
58
+ "access": "public",
59
+ "types": "./dist/types/index.d.ts"
57
60
  },
58
61
  "scripts": {
59
62
  "new": "modern new",
60
63
  "build": "modern build",
61
- "test": "modern test --passWithNoTests"
64
+ "test": "jest --passWithNoTests"
62
65
  },
63
66
  "readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
64
67
  }
package/src/buildWatch.ts CHANGED
@@ -55,7 +55,7 @@ export const runBuildWatch = async (
55
55
  }
56
56
 
57
57
  return watch(
58
- watchDir,
58
+ `${watchDir}/**/*.{js,jsx,ts,tsx}`,
59
59
  async ({ changeType, changedFilePath }) => {
60
60
  emitter.emit(BuildWatchEvent.compiling);
61
61
  if (changeType === WatchChangeType.UNLINK) {
package/src/compiler.ts CHANGED
@@ -38,15 +38,24 @@ export const getDistFilePath = (option: {
38
38
 
39
39
  export const resolveSourceMap = (option: {
40
40
  babelRes: babel.BabelFileResult;
41
+ sourceFilePath: string;
41
42
  distFilePath: string;
42
43
  enableVirtualDist?: boolean;
43
44
  }) => {
44
- const { babelRes, distFilePath, enableVirtualDist = false } = option;
45
+ const {
46
+ babelRes,
47
+ sourceFilePath,
48
+ distFilePath,
49
+ enableVirtualDist = false,
50
+ } = option;
45
51
  const mapLoc = `${distFilePath}.map`;
46
52
  babelRes.code = utils.addSourceMappingUrl(babelRes.code as string, mapLoc);
47
53
 
48
54
  if (babelRes.map) {
49
55
  babelRes.map.file = path.basename(distFilePath);
56
+ babelRes.map.sources = [
57
+ path.relative(path.dirname(distFilePath), sourceFilePath),
58
+ ];
50
59
  }
51
60
 
52
61
  const sourceMapVirtualDist = {
@@ -106,10 +115,20 @@ export const compiler = (option: ISingleFileCompilerOption) => {
106
115
  if (virtualDist) {
107
116
  virtualDist = {
108
117
  ...virtualDist,
109
- ...resolveSourceMap({ babelRes, distFilePath, enableVirtualDist }),
118
+ ...resolveSourceMap({
119
+ babelRes,
120
+ sourceFilePath: filepath,
121
+ distFilePath,
122
+ enableVirtualDist,
123
+ }),
110
124
  };
111
125
  } else {
112
- resolveSourceMap({ babelRes, distFilePath, enableVirtualDist });
126
+ resolveSourceMap({
127
+ babelRes,
128
+ sourceFilePath: filepath,
129
+ distFilePath,
130
+ enableVirtualDist,
131
+ });
113
132
  }
114
133
  }
115
134
 
@@ -24,7 +24,6 @@ describe('test build', () => {
24
24
  await build({ rootDir: srcDir, filenames, distDir });
25
25
  const globFindFiles = glob.sync(`${distDir}/**/*.js`);
26
26
  expect(globFindFiles.length).toBe(1);
27
- fs.removeSync(distDir);
28
27
  });
29
28
 
30
29
  it('build with enableVirtualDist and success', async () => {
@@ -80,7 +79,6 @@ describe('test build', () => {
80
79
  });
81
80
  const globFindFiles = glob.sync(`${distDir}/**/*.js`);
82
81
  expect(globFindFiles.length).toBe(1);
83
- fs.removeSync(distDir);
84
82
  });
85
83
 
86
84
  it('build multiple files and success', async () => {
@@ -39,7 +39,9 @@ describe('test build watch', () => {
39
39
  expect(ret).toBe(null);
40
40
  });
41
41
 
42
- it('runBuildWatch and success', async done => {
42
+ it('runBuildWatch and success', async () => {
43
+ let done: any;
44
+ const promise = new Promise(resolve => (done = resolve));
43
45
  let compiling = false;
44
46
  const emitter = new BuildWatchEmitter();
45
47
  emitter.on(BuildWatchEvent.firstCompiler, (result: ICompilerResult) => {
@@ -65,9 +67,12 @@ describe('test build watch', () => {
65
67
  fs.ensureFileSync(path.join(srcDir, 'far.js'));
66
68
  compiling = true;
67
69
  });
70
+ return promise;
68
71
  });
69
72
 
70
- it('runBuildWatch and fail', async done => {
73
+ it('runBuildWatch and fail', async () => {
74
+ let done: any;
75
+ const promise = new Promise(resolve => (done = resolve));
71
76
  const emitter = new BuildWatchEmitter();
72
77
  emitter.on(BuildWatchEvent.firstCompiler, (result: ICompilerResult) => {
73
78
  expect(result.code).toBe(1);
@@ -89,9 +94,12 @@ describe('test build watch', () => {
89
94
  fs.ensureFileSync(path.join(srcDir, 'error1.js'));
90
95
  fs.writeFileSync(path.join(srcDir, 'error1.js'), 'conta a = 1');
91
96
  });
97
+ return promise;
92
98
  });
93
99
 
94
- it('buildWatch and success', async done => {
100
+ it('buildWatch and success', async () => {
101
+ let done: any;
102
+ const promise = new Promise(resolve => (done = resolve));
95
103
  const emitter = buildWatch({
96
104
  rootDir: srcDir,
97
105
  watchDir: srcDir,
@@ -125,9 +133,12 @@ describe('test build watch', () => {
125
133
  compiling = true;
126
134
  });
127
135
  }
136
+ return promise;
128
137
  });
129
138
 
130
- it('buildWatch and fail', async done => {
139
+ it('buildWatch and fail', async () => {
140
+ let done: any;
141
+ const promise = new Promise(resolve => (done = resolve));
131
142
  const emitter = buildWatch({
132
143
  rootDir: srcDir,
133
144
  watchDir: srcDir,
@@ -161,9 +172,12 @@ describe('test build watch', () => {
161
172
  compiling = true;
162
173
  });
163
174
  }
175
+ return promise;
164
176
  });
165
177
 
166
- it('buildWatch and remove file', async done => {
178
+ it('buildWatch and remove file', async () => {
179
+ let done: any;
180
+ const promise = new Promise(resolve => (done = resolve));
167
181
  const emitter = buildWatch({
168
182
  rootDir: srcDir,
169
183
  watchDir: srcDir,
@@ -190,9 +204,12 @@ describe('test build watch', () => {
190
204
  fs.removeSync(path.join(srcDir, 'far.js'));
191
205
  });
192
206
  }
207
+ return promise;
193
208
  });
194
209
 
195
- it('buildWatch and reRight file', async done => {
210
+ it('buildWatch and reRight file', async () => {
211
+ let done: any;
212
+ const promise = new Promise(resolve => (done = resolve));
196
213
  fs.ensureFileSync(path.join(srcDir, 'error1.js'));
197
214
  fs.writeFileSync(path.join(srcDir, 'error1.js'), 'cast a = 1;');
198
215
  const emitter = buildWatch({
@@ -221,6 +238,7 @@ describe('test build watch', () => {
221
238
  fs.writeFileSync(path.join(srcDir, 'error1.js'), 'const a = 1;');
222
239
  });
223
240
  }
241
+ return promise;
224
242
  });
225
243
 
226
244
  afterEach(() => {
@@ -49,6 +49,7 @@ describe('compiler', () => {
49
49
  const distFilePath = path.join(projectDir, 'dist/far.js');
50
50
  const sourcemap_1 = resolveSourceMap({
51
51
  babelRes: babelRes as babel.BabelFileResult,
52
+ sourceFilePath: path.join(projectDir, 'src/index.js'),
52
53
  distFilePath,
53
54
  enableVirtualDist: true,
54
55
  });
@@ -59,6 +60,7 @@ describe('compiler', () => {
59
60
 
60
61
  const sourcemap_2 = resolveSourceMap({
61
62
  babelRes: babelRes as babel.BabelFileResult,
63
+ sourceFilePath: path.join(projectDir, 'src/index.js'),
62
64
  distFilePath,
63
65
  });
64
66
  expect(fs.readFileSync(sourcemap_2.sourceMapPath, 'utf-8')).toBe(
@@ -7,9 +7,7 @@
7
7
  "outDir": "./out",
8
8
  "emitDeclarationOnly": true,
9
9
  "isolatedModules": true,
10
- "paths": {
11
- "@/*": ["../src/*"]
12
- },
10
+ "paths": {},
13
11
  "types": ["node", "jest"]
14
12
  }
15
13
  }
package/tsconfig.json CHANGED
@@ -7,9 +7,7 @@
7
7
  "outDir": "./out",
8
8
  "emitDeclarationOnly": true,
9
9
  "isolatedModules": true,
10
- "paths": {
11
- "@/*": ["./src/*"]
12
- },
10
+ "paths": {},
13
11
  "types": ["node", "jest"]
14
12
  },
15
13
  "include": ["src"]