@modern-js/node-bundle-require 1.0.0 → 1.1.1
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 -0
- package/README.md +1 -4
- package/dist/js/modern/index.js +19 -9
- package/dist/js/node/index.js +21 -9
- package/dist/types/index.d.ts +1 -0
- package/package.json +3 -3
- package/src/index.ts +17 -6
- package/tests/.eslintrc.js +4 -4
- package/tests/fixture/a.ts +1 -1
- package/tests/fixture/input.ts +2 -2
- package/tests/index.test.ts +18 -6
- package/tests/modern-app-env.d.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @modern-js/1.0.0-rc.19
|
|
2
2
|
|
|
3
|
+
## 1.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0fa83663: support more .env files
|
|
8
|
+
|
|
9
|
+
## 1.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 96119db2: Relese v1.1.0
|
|
14
|
+
|
|
15
|
+
## 1.0.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- fix(require): external regexp
|
|
20
|
+
|
|
3
21
|
## 1.0.0
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -17,10 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
> 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.
|
|
19
19
|
|
|
20
|
-
-
|
|
21
|
-
- [迈入现代 Web 开发](https://zhuanlan.zhihu.com/p/386607009)
|
|
22
|
-
- [现代 Web 开发者问卷调查报告](https://zhuanlan.zhihu.com/p/403206195)
|
|
23
|
-
- [字节跳动是如何落地微前端的](https://mp.weixin.qq.com/s/L9wbfNG5fTXF5bx7dcgj4Q)
|
|
20
|
+
- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)
|
|
24
21
|
|
|
25
22
|
## Getting Started
|
|
26
23
|
|
package/dist/js/modern/index.js
CHANGED
|
@@ -8,7 +8,11 @@ import fs from 'fs/promises';
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import { randomUUID } from 'crypto';
|
|
10
10
|
import { build } from 'esbuild';
|
|
11
|
-
const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/;
|
|
11
|
+
const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/; // Must not start with "/" or "./" or "../"
|
|
12
|
+
// "/test/node_modules/foo"
|
|
13
|
+
// "c:/node_modules/foo"
|
|
14
|
+
|
|
15
|
+
export const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
|
|
12
16
|
const CACHE_DIR = path.relative(process.cwd(), './node_modules/.node-bundle-require');
|
|
13
17
|
|
|
14
18
|
function inferLoader(ext) {
|
|
@@ -102,15 +106,21 @@ export async function bundleRequire(filepath, options) {
|
|
|
102
106
|
{
|
|
103
107
|
name: 'make-all-packages-external',
|
|
104
108
|
|
|
105
|
-
setup(
|
|
106
|
-
|
|
109
|
+
setup(_build) {
|
|
110
|
+
_build.onResolve({
|
|
111
|
+
filter: EXTERNAL_REGEXP
|
|
112
|
+
}, args => {
|
|
113
|
+
let external = true; // FIXME: windows external entrypoint
|
|
107
114
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
115
|
+
if (args.kind === 'entry-point') {
|
|
116
|
+
external = false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
path: args.path,
|
|
121
|
+
external
|
|
122
|
+
};
|
|
123
|
+
});
|
|
114
124
|
}
|
|
115
125
|
|
|
116
126
|
}]
|
package/dist/js/node/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.EXTERNAL_REGEXP = void 0;
|
|
6
7
|
exports.bundleRequire = bundleRequire;
|
|
7
8
|
|
|
8
9
|
var _promises = _interopRequireDefault(require("fs/promises"));
|
|
@@ -21,7 +22,12 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
21
22
|
|
|
22
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; }
|
|
23
24
|
|
|
24
|
-
const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/;
|
|
25
|
+
const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/; // Must not start with "/" or "./" or "../"
|
|
26
|
+
// "/test/node_modules/foo"
|
|
27
|
+
// "c:/node_modules/foo"
|
|
28
|
+
|
|
29
|
+
const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
|
|
30
|
+
exports.EXTERNAL_REGEXP = EXTERNAL_REGEXP;
|
|
25
31
|
|
|
26
32
|
const CACHE_DIR = _path.default.relative(process.cwd(), './node_modules/.node-bundle-require');
|
|
27
33
|
|
|
@@ -116,15 +122,21 @@ async function bundleRequire(filepath, options) {
|
|
|
116
122
|
{
|
|
117
123
|
name: 'make-all-packages-external',
|
|
118
124
|
|
|
119
|
-
setup(
|
|
120
|
-
|
|
125
|
+
setup(_build) {
|
|
126
|
+
_build.onResolve({
|
|
127
|
+
filter: EXTERNAL_REGEXP
|
|
128
|
+
}, args => {
|
|
129
|
+
let external = true; // FIXME: windows external entrypoint
|
|
121
130
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
131
|
+
if (args.kind === 'entry-point') {
|
|
132
|
+
external = false;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
path: args.path,
|
|
137
|
+
external
|
|
138
|
+
};
|
|
139
|
+
});
|
|
128
140
|
}
|
|
129
141
|
|
|
130
142
|
}]
|
package/dist/types/index.d.ts
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.1.1",
|
|
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",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"esbuild": "^0.13.8"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@modern-js/plugin-testing": "^1.
|
|
35
|
-
"@modern-js/module-tools": "^1.
|
|
34
|
+
"@modern-js/plugin-testing": "^1.1.0",
|
|
35
|
+
"@modern-js/module-tools": "^1.1.0",
|
|
36
36
|
"@types/jest": "^26.0.9",
|
|
37
37
|
"@types/node": "^14",
|
|
38
38
|
"typescript": "^4"
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,11 @@ import { build, Loader, Plugin, BuildOptions } from 'esbuild';
|
|
|
5
5
|
|
|
6
6
|
const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/;
|
|
7
7
|
|
|
8
|
+
// Must not start with "/" or "./" or "../"
|
|
9
|
+
// "/test/node_modules/foo"
|
|
10
|
+
// "c:/node_modules/foo"
|
|
11
|
+
export const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
|
|
12
|
+
|
|
8
13
|
const CACHE_DIR = path.relative(
|
|
9
14
|
process.cwd(),
|
|
10
15
|
'./node_modules/.node-bundle-require',
|
|
@@ -128,12 +133,18 @@ export async function bundleRequire(filepath: string, options?: Options) {
|
|
|
128
133
|
// https://github.com/evanw/esbuild/issues/619#issuecomment-751995294
|
|
129
134
|
{
|
|
130
135
|
name: 'make-all-packages-external',
|
|
131
|
-
setup(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
setup(_build) {
|
|
137
|
+
_build.onResolve({ filter: EXTERNAL_REGEXP }, args => {
|
|
138
|
+
let external = true;
|
|
139
|
+
// FIXME: windows external entrypoint
|
|
140
|
+
if (args.kind === 'entry-point') {
|
|
141
|
+
external = false;
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
path: args.path,
|
|
145
|
+
external,
|
|
146
|
+
};
|
|
147
|
+
});
|
|
137
148
|
},
|
|
138
149
|
},
|
|
139
150
|
],
|
package/tests/.eslintrc.js
CHANGED
package/tests/fixture/a.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const filename: string = __filename
|
|
1
|
+
export const filename: string = __filename;
|
package/tests/fixture/input.ts
CHANGED
package/tests/index.test.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import { bundleRequire } from '
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { bundleRequire, EXTERNAL_REGEXP } from '../src';
|
|
3
3
|
|
|
4
|
-
test('
|
|
5
|
-
const result = await bundleRequire(
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
test('require', async () => {
|
|
5
|
+
const result = await bundleRequire(
|
|
6
|
+
path.join(__dirname, './fixture/input.ts'),
|
|
7
|
+
);
|
|
8
|
+
expect(result.default.a.filename.endsWith('a.ts')).toEqual(true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('external regexp', () => {
|
|
12
|
+
expect(EXTERNAL_REGEXP.test('./test')).toBeFalsy();
|
|
13
|
+
expect(EXTERNAL_REGEXP.test('/test')).toBeFalsy();
|
|
14
|
+
expect(EXTERNAL_REGEXP.test('c:/foo')).toBeTruthy();
|
|
15
|
+
expect(EXTERNAL_REGEXP.test('C:/foo')).toBeTruthy();
|
|
16
|
+
expect(EXTERNAL_REGEXP.test('c:/node_modules/foo')).toBeTruthy();
|
|
17
|
+
expect(EXTERNAL_REGEXP.test('foo')).toBeTruthy();
|
|
18
|
+
expect(EXTERNAL_REGEXP.test('/test/node_modules')).toBeFalsy();
|
|
19
|
+
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/// <reference types="@modern-js/module-tools/types" />
|
|
2
|
+
/// <reference types="@modern-js/plugin-testing/type" />
|