@modern-js/node-bundle-require 1.1.2-canary.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 +10 -0
- package/dist/js/modern/index.js +8 -4
- package/dist/js/node/index.js +11 -7
- package/jest.config.js +8 -0
- package/modern.config.js +1 -9
- package/package.json +17 -13
- package/src/index.ts +5 -1
- package/tests/fixture/a.ts +1 -0
- package/tests/index.test.ts +7 -0
- package/tests/tsconfig.json +2 -3
- package/tsconfig.json +1 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @modern-js/1.0.0-rc.19
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cfe11628: Make Modern.js self bootstraping
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 59cbcb77: fix esbuild error when project's tsconfig.json sets "target:es5"
|
|
12
|
+
|
|
3
13
|
## 1.1.1
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/dist/js/modern/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
2
|
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
4
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
7
|
-
import fs from 'fs';
|
|
8
7
|
import path from 'path';
|
|
9
8
|
import { randomUUID } from 'crypto';
|
|
9
|
+
import { fs } from '@modern-js/utils';
|
|
10
10
|
import { build } from 'esbuild';
|
|
11
11
|
const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/; // Must not start with "/" or "./" or "../"
|
|
12
12
|
// "/test/node_modules/foo"
|
|
@@ -39,7 +39,11 @@ export async function bundleRequire(filepath, options) {
|
|
|
39
39
|
outfile,
|
|
40
40
|
format: 'cjs',
|
|
41
41
|
platform: 'node',
|
|
42
|
-
bundle: true
|
|
42
|
+
bundle: true,
|
|
43
|
+
// fix transforming error when the project's tsconfig.json
|
|
44
|
+
// sets `target: "es5"`
|
|
45
|
+
// reference: https://github.com/evanw/esbuild/releases/tag/v0.12.6
|
|
46
|
+
target: 'esnext'
|
|
43
47
|
}, options === null || options === void 0 ? void 0 : options.esbuildOptions), {}, {
|
|
44
48
|
plugins: [...((options === null || options === void 0 ? void 0 : options.esbuildPlugins) || []), // https://github.com/evanw/esbuild/issues/1051#issuecomment-806325487
|
|
45
49
|
{
|
package/dist/js/node/index.js
CHANGED
|
@@ -6,19 +6,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.EXTERNAL_REGEXP = void 0;
|
|
7
7
|
exports.bundleRequire = bundleRequire;
|
|
8
8
|
|
|
9
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
10
|
-
|
|
11
9
|
var _path = _interopRequireDefault(require("path"));
|
|
12
10
|
|
|
13
11
|
var _crypto = require("crypto");
|
|
14
12
|
|
|
13
|
+
var _utils = require("@modern-js/utils");
|
|
14
|
+
|
|
15
15
|
var _esbuild = require("esbuild");
|
|
16
16
|
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
18
|
|
|
19
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
19
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
20
20
|
|
|
21
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
21
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
22
22
|
|
|
23
23
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
24
24
|
|
|
@@ -55,7 +55,11 @@ async function bundleRequire(filepath, options) {
|
|
|
55
55
|
outfile,
|
|
56
56
|
format: 'cjs',
|
|
57
57
|
platform: 'node',
|
|
58
|
-
bundle: true
|
|
58
|
+
bundle: true,
|
|
59
|
+
// fix transforming error when the project's tsconfig.json
|
|
60
|
+
// sets `target: "es5"`
|
|
61
|
+
// reference: https://github.com/evanw/esbuild/releases/tag/v0.12.6
|
|
62
|
+
target: 'esnext'
|
|
59
63
|
}, options === null || options === void 0 ? void 0 : options.esbuildOptions), {}, {
|
|
60
64
|
plugins: [...((options === null || options === void 0 ? void 0 : options.esbuildPlugins) || []), // https://github.com/evanw/esbuild/issues/1051#issuecomment-806325487
|
|
61
65
|
{
|
|
@@ -110,7 +114,7 @@ async function bundleRequire(filepath, options) {
|
|
|
110
114
|
ctx.onLoad({
|
|
111
115
|
filter: JS_EXT_RE
|
|
112
116
|
}, async args => {
|
|
113
|
-
const contents =
|
|
117
|
+
const contents = _utils.fs.readFileSync(args.path, 'utf-8');
|
|
114
118
|
|
|
115
119
|
return {
|
|
116
120
|
contents: contents.replace(/\b__filename\b/g, JSON.stringify(args.path)).replace(/\b__dirname\b/g, JSON.stringify(_path.default.dirname(args.path))).replace(/\bimport\.meta\.url\b/g, JSON.stringify(`file://${args.path}`)),
|
|
@@ -149,7 +153,7 @@ async function bundleRequire(filepath, options) {
|
|
|
149
153
|
mod = await req(outfile);
|
|
150
154
|
} finally {
|
|
151
155
|
// Remove the outfile after executed
|
|
152
|
-
|
|
156
|
+
_utils.fs.unlinkSync(outfile);
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
return mod;
|
package/jest.config.js
ADDED
package/modern.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/node-bundle-require",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|
|
@@ -20,28 +20,25 @@
|
|
|
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
|
},
|
|
26
27
|
"default": "./dist/js/treeshaking/index.js"
|
|
27
28
|
}
|
|
28
29
|
},
|
|
29
|
-
"scripts": {
|
|
30
|
-
"prepare": "pnpm build",
|
|
31
|
-
"new": "modern new",
|
|
32
|
-
"build": "modern build",
|
|
33
|
-
"test": "modern test --passWithNoTests"
|
|
34
|
-
},
|
|
35
30
|
"dependencies": {
|
|
36
31
|
"@babel/runtime": "^7",
|
|
37
32
|
"esbuild": "^0.13.8"
|
|
38
33
|
},
|
|
39
34
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@modern-js/
|
|
35
|
+
"@scripts/build": "0.0.0",
|
|
36
|
+
"@modern-js/utils": "^1.2.0",
|
|
42
37
|
"@types/jest": "^26.0.9",
|
|
43
38
|
"@types/node": "^14",
|
|
44
|
-
"typescript": "^4"
|
|
39
|
+
"typescript": "^4",
|
|
40
|
+
"jest": "^27",
|
|
41
|
+
"@scripts/jest-config": "0.0.0"
|
|
45
42
|
},
|
|
46
43
|
"sideEffects": false,
|
|
47
44
|
"modernConfig": {
|
|
@@ -51,6 +48,13 @@
|
|
|
51
48
|
},
|
|
52
49
|
"publishConfig": {
|
|
53
50
|
"registry": "https://registry.npmjs.org/",
|
|
54
|
-
"access": "public"
|
|
55
|
-
|
|
56
|
-
}
|
|
51
|
+
"access": "public",
|
|
52
|
+
"types": "./dist/types/index.d.ts"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"new": "modern new",
|
|
56
|
+
"build": "modern build",
|
|
57
|
+
"test": "jest --passWithNoTests"
|
|
58
|
+
},
|
|
59
|
+
"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"
|
|
60
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
1
|
import path from 'path';
|
|
3
2
|
import { randomUUID } from 'crypto';
|
|
3
|
+
import { fs } from '@modern-js/utils';
|
|
4
4
|
import { build, Loader, Plugin, BuildOptions } from 'esbuild';
|
|
5
5
|
|
|
6
6
|
const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/;
|
|
@@ -66,6 +66,10 @@ export async function bundleRequire(filepath: string, options?: Options) {
|
|
|
66
66
|
format: 'cjs',
|
|
67
67
|
platform: 'node',
|
|
68
68
|
bundle: true,
|
|
69
|
+
// fix transforming error when the project's tsconfig.json
|
|
70
|
+
// sets `target: "es5"`
|
|
71
|
+
// reference: https://github.com/evanw/esbuild/releases/tag/v0.12.6
|
|
72
|
+
target: 'esnext',
|
|
69
73
|
...options?.esbuildOptions,
|
|
70
74
|
plugins: [
|
|
71
75
|
...(options?.esbuildPlugins || []),
|
package/tests/fixture/a.ts
CHANGED
package/tests/index.test.ts
CHANGED
|
@@ -5,7 +5,14 @@ test('require', async () => {
|
|
|
5
5
|
const result = await bundleRequire(
|
|
6
6
|
path.join(__dirname, './fixture/input.ts'),
|
|
7
7
|
);
|
|
8
|
+
// when tsconfig.json sets `compilerOptions.target` to `es5`
|
|
9
|
+
// normally it will met error
|
|
10
|
+
// So we need to manually set esbuild's target to esnext to avoid that
|
|
11
|
+
// These two cases above use ES6+ ability, to test whether esbuild successfuly
|
|
12
|
+
// works on non-ES5 files
|
|
13
|
+
// reference: https://github.com/evanw/esbuild/releases/tag/v0.12.6
|
|
8
14
|
expect(result.default.a.filename.endsWith('a.ts')).toEqual(true);
|
|
15
|
+
expect(result.default.a.showFileName().endsWith('a.ts')).toEqual(true);
|
|
9
16
|
});
|
|
10
17
|
|
|
11
18
|
describe('external regexp', () => {
|
package/tests/tsconfig.json
CHANGED