@modern-js/node-bundle-require 1.0.2 → 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 +18 -2
- package/dist/js/modern/index.js +10 -6
- package/dist/js/node/index.js +12 -7
- package/jest.config.js +8 -0
- package/modern.config.js +1 -9
- package/package.json +12 -7
- package/src/index.ts +7 -3
- 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,10 +1,26 @@
|
|
|
1
1
|
# @modern-js/1.0.0-rc.19
|
|
2
2
|
|
|
3
|
-
## 1.0
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cfe11628: Make Modern.js self bootstraping
|
|
4
8
|
|
|
5
9
|
### Patch Changes
|
|
6
10
|
|
|
7
|
-
-
|
|
11
|
+
- 59cbcb77: fix esbuild error when project's tsconfig.json sets "target:es5"
|
|
12
|
+
|
|
13
|
+
## 1.1.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 0fa83663: support more .env files
|
|
18
|
+
|
|
19
|
+
## 1.1.0
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- 96119db2: Relese v1.1.0
|
|
8
24
|
|
|
9
25
|
## 1.0.1
|
|
10
26
|
|
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/promises';
|
|
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
|
{
|
|
@@ -94,7 +98,7 @@ export async function bundleRequire(filepath, options) {
|
|
|
94
98
|
ctx.onLoad({
|
|
95
99
|
filter: JS_EXT_RE
|
|
96
100
|
}, async args => {
|
|
97
|
-
const contents =
|
|
101
|
+
const contents = fs.readFileSync(args.path, 'utf-8');
|
|
98
102
|
return {
|
|
99
103
|
contents: contents.replace(/\b__filename\b/g, JSON.stringify(args.path)).replace(/\b__dirname\b/g, JSON.stringify(path.dirname(args.path))).replace(/\bimport\.meta\.url\b/g, JSON.stringify(`file://${args.path}`)),
|
|
100
104
|
loader: inferLoader(path.extname(args.path))
|
|
@@ -132,7 +136,7 @@ export async function bundleRequire(filepath, options) {
|
|
|
132
136
|
mod = await req(outfile);
|
|
133
137
|
} finally {
|
|
134
138
|
// Remove the outfile after executed
|
|
135
|
-
|
|
139
|
+
fs.unlinkSync(outfile);
|
|
136
140
|
}
|
|
137
141
|
|
|
138
142
|
return mod;
|
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 _promises = _interopRequireDefault(require("fs/promises"));
|
|
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,8 @@ 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');
|
|
118
|
+
|
|
114
119
|
return {
|
|
115
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}`)),
|
|
116
121
|
loader: inferLoader(_path.default.extname(args.path))
|
|
@@ -148,7 +153,7 @@ async function bundleRequire(filepath, options) {
|
|
|
148
153
|
mod = await req(outfile);
|
|
149
154
|
} finally {
|
|
150
155
|
// Remove the outfile after executed
|
|
151
|
-
|
|
156
|
+
_utils.fs.unlinkSync(outfile);
|
|
152
157
|
}
|
|
153
158
|
|
|
154
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.0
|
|
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,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
|
},
|
|
@@ -31,11 +32,13 @@
|
|
|
31
32
|
"esbuild": "^0.13.8"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"@modern-js/
|
|
35
|
+
"@scripts/build": "0.0.0",
|
|
36
|
+
"@modern-js/utils": "^1.2.0",
|
|
36
37
|
"@types/jest": "^26.0.9",
|
|
37
38
|
"@types/node": "^14",
|
|
38
|
-
"typescript": "^4"
|
|
39
|
+
"typescript": "^4",
|
|
40
|
+
"jest": "^27",
|
|
41
|
+
"@scripts/jest-config": "0.0.0"
|
|
39
42
|
},
|
|
40
43
|
"sideEffects": false,
|
|
41
44
|
"modernConfig": {
|
|
@@ -45,11 +48,13 @@
|
|
|
45
48
|
},
|
|
46
49
|
"publishConfig": {
|
|
47
50
|
"registry": "https://registry.npmjs.org/",
|
|
48
|
-
"access": "public"
|
|
51
|
+
"access": "public",
|
|
52
|
+
"types": "./dist/types/index.d.ts"
|
|
49
53
|
},
|
|
50
54
|
"scripts": {
|
|
51
55
|
"new": "modern new",
|
|
52
56
|
"build": "modern build",
|
|
53
|
-
"test": "
|
|
54
|
-
}
|
|
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"
|
|
55
60
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
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 || []),
|
|
@@ -113,7 +117,7 @@ export async function bundleRequire(filepath: string, options?: Options) {
|
|
|
113
117
|
name: 'replace-path',
|
|
114
118
|
setup(ctx) {
|
|
115
119
|
ctx.onLoad({ filter: JS_EXT_RE }, async args => {
|
|
116
|
-
const contents =
|
|
120
|
+
const contents = fs.readFileSync(args.path, 'utf-8');
|
|
117
121
|
return {
|
|
118
122
|
contents: contents
|
|
119
123
|
.replace(/\b__filename\b/g, JSON.stringify(args.path))
|
|
@@ -156,7 +160,7 @@ export async function bundleRequire(filepath: string, options?: Options) {
|
|
|
156
160
|
mod = await req(outfile);
|
|
157
161
|
} finally {
|
|
158
162
|
// Remove the outfile after executed
|
|
159
|
-
|
|
163
|
+
fs.unlinkSync(outfile);
|
|
160
164
|
}
|
|
161
165
|
|
|
162
166
|
return mod;
|
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