@modern-js/node-bundle-require 1.3.0 → 1.3.3
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 +24 -0
- package/dist/js/modern/index.js +16 -2
- package/dist/js/node/index.js +15 -2
- package/package.json +28 -6
- package/jest.config.js +0 -7
- package/modern.config.js +0 -6
- package/tests/.eslintrc.js +0 -6
- package/tests/fixture/a.ts +0 -2
- package/tests/fixture/input.ts +0 -5
- package/tests/index.test.ts +0 -27
- package/tests/modern-app-env.d.ts +0 -2
- package/tests/tsconfig.json +0 -10
- package/tsconfig.json +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @modern-js/node-bundle-require
|
|
2
2
|
|
|
3
|
+
## 1.3.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d32f35134: chore: add modern/jest/eslint/ts config files to .npmignore
|
|
8
|
+
|
|
9
|
+
## 1.3.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 6c1438d2: fix: missing peer deps warnings
|
|
14
|
+
- 895fa0ff: chore: using "workspace:\*" in devDependencies
|
|
15
|
+
|
|
16
|
+
## 1.3.1
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- b8599d09: fix: failed to generate webpack cache
|
|
21
|
+
- 6cffe99d: chore:
|
|
22
|
+
remove react eslint rules for `modern-js` rule set.
|
|
23
|
+
add .eslintrc for each package to speed up linting
|
|
24
|
+
- 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
|
|
25
|
+
- 60f7d8bf: feat: add tests dir to npmignore
|
|
26
|
+
|
|
3
27
|
## 1.3.0
|
|
4
28
|
|
|
5
29
|
### Minor Changes
|
package/dist/js/modern/index.js
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
import { fs } from '@modern-js/utils';
|
|
2
2
|
import { bundle } from "./bundle";
|
|
3
3
|
export { bundle };
|
|
4
|
+
|
|
5
|
+
function deleteRequireCache(path) {
|
|
6
|
+
if (require.cache[path]) {
|
|
7
|
+
delete require.cache[path];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (module.children) {
|
|
11
|
+
module.children = module.children.filter(item => item.filename !== path);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
4
15
|
export async function bundleRequire(filepath, options) {
|
|
5
16
|
const configFile = await bundle(filepath, options);
|
|
6
17
|
let mod;
|
|
7
18
|
const req = (options === null || options === void 0 ? void 0 : options.require) || require;
|
|
8
19
|
|
|
9
20
|
try {
|
|
10
|
-
mod = await req(configFile);
|
|
21
|
+
mod = await req(configFile); // Webpack will check require history for persistent cache.
|
|
22
|
+
// If webpack can not resolve the file, the previous cache pack will become invalid.
|
|
23
|
+
// The bundled file is temporary, so we should clear the require history to avoid breaking the webpack cache.
|
|
24
|
+
|
|
25
|
+
deleteRequireCache(configFile);
|
|
11
26
|
} finally {
|
|
12
|
-
// Remove the configFile after executed
|
|
13
27
|
fs.unlinkSync(configFile);
|
|
14
28
|
}
|
|
15
29
|
|
package/dist/js/node/index.js
CHANGED
|
@@ -15,15 +15,28 @@ var _utils = require("@modern-js/utils");
|
|
|
15
15
|
|
|
16
16
|
var _bundle = require("./bundle");
|
|
17
17
|
|
|
18
|
+
function deleteRequireCache(path) {
|
|
19
|
+
if (require.cache[path]) {
|
|
20
|
+
delete require.cache[path];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (module.children) {
|
|
24
|
+
module.children = module.children.filter(item => item.filename !== path);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
18
28
|
async function bundleRequire(filepath, options) {
|
|
19
29
|
const configFile = await (0, _bundle.bundle)(filepath, options);
|
|
20
30
|
let mod;
|
|
21
31
|
const req = (options === null || options === void 0 ? void 0 : options.require) || require;
|
|
22
32
|
|
|
23
33
|
try {
|
|
24
|
-
mod = await req(configFile);
|
|
34
|
+
mod = await req(configFile); // Webpack will check require history for persistent cache.
|
|
35
|
+
// If webpack can not resolve the file, the previous cache pack will become invalid.
|
|
36
|
+
// The bundled file is temporary, so we should clear the require history to avoid breaking the webpack cache.
|
|
37
|
+
|
|
38
|
+
deleteRequireCache(configFile);
|
|
25
39
|
} finally {
|
|
26
|
-
// Remove the configFile after executed
|
|
27
40
|
_utils.fs.unlinkSync(configFile);
|
|
28
41
|
}
|
|
29
42
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/node-bundle-require",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "The meta-framework suite designed from scratch for frontend-focused modern web development.",
|
|
5
5
|
"homepage": "https://modernjs.dev",
|
|
6
6
|
"bugs": "https://github.com/modern-js-dev/modern.js/issues",
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@babel/runtime": "^7",
|
|
43
|
-
"esbuild": "^0.
|
|
43
|
+
"esbuild": "^0.14.38",
|
|
44
44
|
"nanoid": "^3.3.2"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@modern-js/utils": "
|
|
47
|
+
"@modern-js/utils": "1.7.3",
|
|
48
48
|
"@scripts/build": "0.0.0",
|
|
49
49
|
"@scripts/jest-config": "0.0.0",
|
|
50
|
-
"@types/jest": "^
|
|
50
|
+
"@types/jest": "^27",
|
|
51
51
|
"@types/node": "^14",
|
|
52
52
|
"jest": "^27",
|
|
53
53
|
"typescript": "^4"
|
|
@@ -57,10 +57,32 @@
|
|
|
57
57
|
"registry": "https://registry.npmjs.org/",
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
|
+
"wireit": {
|
|
61
|
+
"build": {
|
|
62
|
+
"command": "modern build",
|
|
63
|
+
"files": [
|
|
64
|
+
"src/**/*",
|
|
65
|
+
"tsconfig.json",
|
|
66
|
+
"package.json"
|
|
67
|
+
],
|
|
68
|
+
"output": [
|
|
69
|
+
"dist/**/*"
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
"test": {
|
|
73
|
+
"command": "jest --passWithNoTests",
|
|
74
|
+
"files": [
|
|
75
|
+
"src/**/*",
|
|
76
|
+
"tsconfig.json",
|
|
77
|
+
"package.json"
|
|
78
|
+
],
|
|
79
|
+
"output": []
|
|
80
|
+
}
|
|
81
|
+
},
|
|
60
82
|
"scripts": {
|
|
61
83
|
"new": "modern new",
|
|
62
|
-
"build": "
|
|
63
|
-
"test": "
|
|
84
|
+
"build": "wireit",
|
|
85
|
+
"test": "wireit"
|
|
64
86
|
},
|
|
65
87
|
"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"
|
|
66
88
|
}
|
package/jest.config.js
DELETED
package/modern.config.js
DELETED
package/tests/.eslintrc.js
DELETED
package/tests/fixture/a.ts
DELETED
package/tests/fixture/input.ts
DELETED
package/tests/index.test.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { bundleRequire } from '../src';
|
|
3
|
-
import { EXTERNAL_REGEXP } from '../src/bundle';
|
|
4
|
-
|
|
5
|
-
test('require', async () => {
|
|
6
|
-
const result = await bundleRequire(
|
|
7
|
-
path.join(__dirname, './fixture/input.ts'),
|
|
8
|
-
);
|
|
9
|
-
// when tsconfig.json sets `compilerOptions.target` to `es5`
|
|
10
|
-
// normally it will met error
|
|
11
|
-
// So we need to manually set esbuild's target to esnext to avoid that
|
|
12
|
-
// These two cases above use ES6+ ability, to test whether esbuild successfuly
|
|
13
|
-
// works on non-ES5 files
|
|
14
|
-
// reference: https://github.com/evanw/esbuild/releases/tag/v0.12.6
|
|
15
|
-
expect(result.default.a.filename.endsWith('a.ts')).toEqual(true);
|
|
16
|
-
expect(result.default.a.showFileName().endsWith('a.ts')).toEqual(true);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('external regexp', () => {
|
|
20
|
-
expect(EXTERNAL_REGEXP.test('./test')).toBeFalsy();
|
|
21
|
-
expect(EXTERNAL_REGEXP.test('/test')).toBeFalsy();
|
|
22
|
-
expect(EXTERNAL_REGEXP.test('c:/foo')).toBeTruthy();
|
|
23
|
-
expect(EXTERNAL_REGEXP.test('C:/foo')).toBeTruthy();
|
|
24
|
-
expect(EXTERNAL_REGEXP.test('c:/node_modules/foo')).toBeTruthy();
|
|
25
|
-
expect(EXTERNAL_REGEXP.test('foo')).toBeTruthy();
|
|
26
|
-
expect(EXTERNAL_REGEXP.test('/test/node_modules')).toBeFalsy();
|
|
27
|
-
});
|
package/tests/tsconfig.json
DELETED