@modern-js/node-bundle-require 1.2.0 → 1.2.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 +12 -0
- package/dist/js/modern/index.js +2 -4
- package/dist/js/node/index.js +3 -5
- package/package.json +5 -5
- package/src/.eslintrc.json +0 -3
- package/src/index.ts +0 -167
- package/src/modern-app-env.d.ts +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @modern-js/1.0.0-rc.19
|
|
2
2
|
|
|
3
|
+
## 1.2.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0f4b9b05: fix: release @modern-js/node-bundle-require for change randomUUID to nanoid
|
|
8
|
+
|
|
9
|
+
## 1.2.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 83166714: change .npmignore
|
|
14
|
+
|
|
3
15
|
## 1.2.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/js/modern/index.js
CHANGED
|
@@ -5,9 +5,9 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
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
7
|
import path from 'path';
|
|
8
|
-
import { randomUUID } from 'crypto';
|
|
9
8
|
import { fs } from '@modern-js/utils';
|
|
10
9
|
import { build } from 'esbuild';
|
|
10
|
+
import { nanoid } from 'nanoid';
|
|
11
11
|
const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/; // Must not start with "/" or "./" or "../"
|
|
12
12
|
// "/test/node_modules/foo"
|
|
13
13
|
// "c:/node_modules/foo"
|
|
@@ -23,9 +23,7 @@ function inferLoader(ext) {
|
|
|
23
23
|
return ext.slice(1);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const defaultGetOutputFile = filepath => path.resolve(CACHE_DIR, `${filepath}-${Date.now()}.${
|
|
27
|
-
disableEntropyCache: true
|
|
28
|
-
})}.bundled.cjs`);
|
|
26
|
+
const defaultGetOutputFile = filepath => path.resolve(CACHE_DIR, `${filepath}-${Date.now()}.${nanoid()}.bundled.cjs`);
|
|
29
27
|
|
|
30
28
|
export async function bundleRequire(filepath, options) {
|
|
31
29
|
if (!JS_EXT_RE.test(filepath)) {
|
package/dist/js/node/index.js
CHANGED
|
@@ -8,12 +8,12 @@ exports.bundleRequire = bundleRequire;
|
|
|
8
8
|
|
|
9
9
|
var _path = _interopRequireDefault(require("path"));
|
|
10
10
|
|
|
11
|
-
var _crypto = require("crypto");
|
|
12
|
-
|
|
13
11
|
var _utils = require("@modern-js/utils");
|
|
14
12
|
|
|
15
13
|
var _esbuild = require("esbuild");
|
|
16
14
|
|
|
15
|
+
var _nanoid = require("nanoid");
|
|
16
|
+
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
18
|
|
|
19
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; }
|
|
@@ -39,9 +39,7 @@ function inferLoader(ext) {
|
|
|
39
39
|
return ext.slice(1);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
const defaultGetOutputFile = filepath => _path.default.resolve(CACHE_DIR, `${filepath}-${Date.now()}.${(0,
|
|
43
|
-
disableEntropyCache: true
|
|
44
|
-
})}.bundled.cjs`);
|
|
42
|
+
const defaultGetOutputFile = filepath => _path.default.resolve(CACHE_DIR, `${filepath}-${Date.now()}.${(0, _nanoid.nanoid)()}.bundled.cjs`);
|
|
45
43
|
|
|
46
44
|
async function bundleRequire(filepath, options) {
|
|
47
45
|
if (!JS_EXT_RE.test(filepath)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/node-bundle-require",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.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",
|
|
@@ -29,11 +29,12 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "^7",
|
|
32
|
-
"esbuild": "^0.13.8"
|
|
32
|
+
"esbuild": "^0.13.8",
|
|
33
|
+
"nanoid": "^3.3.1"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@scripts/build": "0.0.0",
|
|
36
|
-
"@modern-js/utils": "^1.
|
|
37
|
+
"@modern-js/utils": "^1.3.6",
|
|
37
38
|
"@types/jest": "^26.0.9",
|
|
38
39
|
"@types/node": "^14",
|
|
39
40
|
"typescript": "^4",
|
|
@@ -48,8 +49,7 @@
|
|
|
48
49
|
},
|
|
49
50
|
"publishConfig": {
|
|
50
51
|
"registry": "https://registry.npmjs.org/",
|
|
51
|
-
"access": "public"
|
|
52
|
-
"types": "./dist/types/index.d.ts"
|
|
52
|
+
"access": "public"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"new": "modern new",
|
package/src/.eslintrc.json
DELETED
package/src/index.ts
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { randomUUID } from 'crypto';
|
|
3
|
-
import { fs } from '@modern-js/utils';
|
|
4
|
-
import { build, Loader, Plugin, BuildOptions } from 'esbuild';
|
|
5
|
-
|
|
6
|
-
const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/;
|
|
7
|
-
|
|
8
|
-
// Must not start with "/" or "./" or "../"
|
|
9
|
-
// "/test/node_modules/foo"
|
|
10
|
-
// "c:/node_modules/foo"
|
|
11
|
-
export const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
|
|
12
|
-
|
|
13
|
-
const CACHE_DIR = path.relative(
|
|
14
|
-
process.cwd(),
|
|
15
|
-
'./node_modules/.node-bundle-require',
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
function inferLoader(ext: string): Loader {
|
|
19
|
-
if (ext === '.mjs' || ext === '.cjs') {
|
|
20
|
-
return 'js';
|
|
21
|
-
}
|
|
22
|
-
return ext.slice(1) as Loader;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface Options {
|
|
26
|
-
/**
|
|
27
|
-
* The `require` function that is used to load the output file
|
|
28
|
-
* Default to the global `require` function
|
|
29
|
-
* This function can be asynchronous, i.e. returns a Promise
|
|
30
|
-
*/
|
|
31
|
-
require?: (outfile: string) => any;
|
|
32
|
-
/**
|
|
33
|
-
* esbuild options
|
|
34
|
-
*/
|
|
35
|
-
esbuildOptions?: BuildOptions;
|
|
36
|
-
/**
|
|
37
|
-
* esbuild plugin
|
|
38
|
-
*/
|
|
39
|
-
esbuildPlugins?: Plugin[];
|
|
40
|
-
/**
|
|
41
|
-
* Get the path to the output file
|
|
42
|
-
* By default we simply replace the extension with `.bundled.cjs`
|
|
43
|
-
*/
|
|
44
|
-
getOutputFile?: (filepath: string) => string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const defaultGetOutputFile = (filepath: string) =>
|
|
48
|
-
path.resolve(
|
|
49
|
-
CACHE_DIR,
|
|
50
|
-
`${filepath}-${Date.now()}.${randomUUID({
|
|
51
|
-
disableEntropyCache: true,
|
|
52
|
-
})}.bundled.cjs`,
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
export async function bundleRequire(filepath: string, options?: Options) {
|
|
56
|
-
if (!JS_EXT_RE.test(filepath)) {
|
|
57
|
-
throw new Error(`${filepath} is not a valid JS file`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const getOutputFile = options?.getOutputFile || defaultGetOutputFile;
|
|
61
|
-
const outfile = getOutputFile(filepath);
|
|
62
|
-
|
|
63
|
-
await build({
|
|
64
|
-
entryPoints: [filepath],
|
|
65
|
-
outfile,
|
|
66
|
-
format: 'cjs',
|
|
67
|
-
platform: 'node',
|
|
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',
|
|
73
|
-
...options?.esbuildOptions,
|
|
74
|
-
plugins: [
|
|
75
|
-
...(options?.esbuildPlugins || []),
|
|
76
|
-
// https://github.com/evanw/esbuild/issues/1051#issuecomment-806325487
|
|
77
|
-
{
|
|
78
|
-
name: 'native-node-modules',
|
|
79
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
80
|
-
setup(build) {
|
|
81
|
-
// If a ".node" file is imported within a module in the "file" namespace, resolve
|
|
82
|
-
// it to an absolute path and put it into the "node-file" virtual namespace.
|
|
83
|
-
build.onResolve({ filter: /\.node$/, namespace: 'file' }, args => ({
|
|
84
|
-
path: require.resolve(args.path, { paths: [args.resolveDir] }),
|
|
85
|
-
namespace: 'node-file',
|
|
86
|
-
}));
|
|
87
|
-
|
|
88
|
-
// Files in the "node-file" virtual namespace call "require()" on the
|
|
89
|
-
// path from esbuild of the ".node" file in the output directory.
|
|
90
|
-
build.onLoad({ filter: /.*/, namespace: 'node-file' }, args => ({
|
|
91
|
-
contents: `
|
|
92
|
-
import path from ${JSON.stringify(args.path)}
|
|
93
|
-
try { module.exports = require(path) }
|
|
94
|
-
catch {}
|
|
95
|
-
`,
|
|
96
|
-
}));
|
|
97
|
-
|
|
98
|
-
// If a ".node" file is imported within a module in the "node-file" namespace, put
|
|
99
|
-
// it in the "file" namespace where esbuild's default loading behavior will handle
|
|
100
|
-
// it. It is already an absolute path since we resolved it to one above.
|
|
101
|
-
build.onResolve(
|
|
102
|
-
{ filter: /\.node$/, namespace: 'node-file' },
|
|
103
|
-
args => ({
|
|
104
|
-
path: args.path,
|
|
105
|
-
namespace: 'file',
|
|
106
|
-
}),
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
// Tell esbuild's default loading behavior to use the "file" loader for
|
|
110
|
-
// these ".node" files.
|
|
111
|
-
const opts = build.initialOptions;
|
|
112
|
-
opts.loader = opts.loader || {};
|
|
113
|
-
opts.loader['.node'] = 'file';
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
name: 'replace-path',
|
|
118
|
-
setup(ctx) {
|
|
119
|
-
ctx.onLoad({ filter: JS_EXT_RE }, async args => {
|
|
120
|
-
const contents = fs.readFileSync(args.path, 'utf-8');
|
|
121
|
-
return {
|
|
122
|
-
contents: contents
|
|
123
|
-
.replace(/\b__filename\b/g, JSON.stringify(args.path))
|
|
124
|
-
.replace(
|
|
125
|
-
/\b__dirname\b/g,
|
|
126
|
-
JSON.stringify(path.dirname(args.path)),
|
|
127
|
-
)
|
|
128
|
-
.replace(
|
|
129
|
-
/\bimport\.meta\.url\b/g,
|
|
130
|
-
JSON.stringify(`file://${args.path}`),
|
|
131
|
-
),
|
|
132
|
-
loader: inferLoader(path.extname(args.path)),
|
|
133
|
-
};
|
|
134
|
-
});
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
// https://github.com/evanw/esbuild/issues/619#issuecomment-751995294
|
|
138
|
-
{
|
|
139
|
-
name: 'make-all-packages-external',
|
|
140
|
-
setup(_build) {
|
|
141
|
-
_build.onResolve({ filter: EXTERNAL_REGEXP }, args => {
|
|
142
|
-
let external = true;
|
|
143
|
-
// FIXME: windows external entrypoint
|
|
144
|
-
if (args.kind === 'entry-point') {
|
|
145
|
-
external = false;
|
|
146
|
-
}
|
|
147
|
-
return {
|
|
148
|
-
path: args.path,
|
|
149
|
-
external,
|
|
150
|
-
};
|
|
151
|
-
});
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
],
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
let mod: any;
|
|
158
|
-
const req = options?.require || require;
|
|
159
|
-
try {
|
|
160
|
-
mod = await req(outfile);
|
|
161
|
-
} finally {
|
|
162
|
-
// Remove the outfile after executed
|
|
163
|
-
fs.unlinkSync(outfile);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return mod;
|
|
167
|
-
}
|
package/src/modern-app-env.d.ts
DELETED