rolldown-require 1.0.0 → 1.0.2
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/README.md +19 -20
- package/dist/index.cjs +41 -76
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.mjs +67 -110
- package/package.json +12 -3
- package/dist/chunk-Q6XJHTDB.cjs +0 -15
- package/dist/chunk-WUKYLWAZ.mjs +0 -0
- package/dist/false-G5OFYI37.mjs +0 -7
- package/dist/false-SI6OY5LO.cjs +0 -9
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://npm.im/rolldown-require) [](https://npm.im/rolldown-require) [](https://www.jsdocs.io/package/rolldown-require)
|
|
6
6
|
|
|
7
|
+
## [HomePage](https://github.com/weapp-vite/weapp-vite/tree/main/packages/rolldown-require)
|
|
8
|
+
|
|
7
9
|
## Use Case
|
|
8
10
|
|
|
9
11
|
Recently, the [rolldown-vite](https://github.com/vite/rolldown-vite) project needed to load user-provided configuration files. However, simply using `require()` was not sufficient, because the configuration files might not be `CommonJS` modules—they could be in `.mjs` format or even written in `TypeScript`. That’s where the `rolldown-require` package comes in, enabling you to load configuration files of any format.
|
|
@@ -41,6 +43,8 @@ const { mod } = await bundleRequire({
|
|
|
41
43
|
## Options
|
|
42
44
|
|
|
43
45
|
```ts
|
|
46
|
+
import type { ExternalOption, InputOptions, OutputOptions } from 'rolldown'
|
|
47
|
+
|
|
44
48
|
export type RequireFunction = (
|
|
45
49
|
outfile: string,
|
|
46
50
|
ctx: { format: 'cjs' | 'esm' },
|
|
@@ -48,13 +52,6 @@ export type RequireFunction = (
|
|
|
48
52
|
|
|
49
53
|
export type GetOutputFile = (filepath: string, format: 'esm' | 'cjs') => string
|
|
50
54
|
|
|
51
|
-
export type RebuildCallback = (
|
|
52
|
-
error: RollupError | null,
|
|
53
|
-
result: RolldownOutput | null,
|
|
54
|
-
) => void
|
|
55
|
-
|
|
56
|
-
export type ReadFile = (filepath: string) => string
|
|
57
|
-
|
|
58
55
|
export interface Options {
|
|
59
56
|
cwd?: string
|
|
60
57
|
/**
|
|
@@ -62,46 +59,48 @@ export interface Options {
|
|
|
62
59
|
*/
|
|
63
60
|
filepath: string
|
|
64
61
|
/**
|
|
65
|
-
* The `require` function used to load the output file
|
|
66
|
-
*
|
|
67
|
-
* This function can be asynchronous
|
|
62
|
+
* The `require` function that is used to load the output file
|
|
63
|
+
* Default to the global `require` function
|
|
64
|
+
* This function can be asynchronous, i.e. returns a Promise
|
|
68
65
|
*/
|
|
69
66
|
require?: RequireFunction
|
|
70
67
|
/**
|
|
71
68
|
* esbuild options
|
|
72
69
|
*
|
|
73
70
|
*/
|
|
74
|
-
rolldownOptions?:
|
|
71
|
+
rolldownOptions?: {
|
|
72
|
+
input?: InputOptions
|
|
73
|
+
output?: OutputOptions
|
|
74
|
+
}
|
|
75
|
+
|
|
75
76
|
/**
|
|
76
77
|
* Get the path to the output file
|
|
77
|
-
* By default
|
|
78
|
+
* By default we simply replace the extension with `.bundled_{randomId}.js`
|
|
78
79
|
*/
|
|
79
80
|
getOutputFile?: GetOutputFile
|
|
80
|
-
/**
|
|
81
|
-
* Enable watching and call the callback after each rebuild
|
|
82
|
-
*/
|
|
83
81
|
|
|
84
82
|
/** External packages */
|
|
85
83
|
external?: ExternalOption
|
|
86
84
|
|
|
87
85
|
/**
|
|
88
|
-
* A custom tsconfig path to read
|
|
86
|
+
* A custom tsconfig path to read `paths` option
|
|
89
87
|
*
|
|
90
|
-
* Set to `false` to disable tsconfig
|
|
88
|
+
* Set to `false` to disable tsconfig
|
|
91
89
|
*/
|
|
92
90
|
tsconfig?: string | false
|
|
93
91
|
|
|
94
92
|
/**
|
|
95
|
-
* Preserve
|
|
96
|
-
*
|
|
93
|
+
* Preserve compiled temporary file for debugging
|
|
94
|
+
* Default to `process.env.BUNDLE_REQUIRE_PRESERVE`
|
|
97
95
|
*/
|
|
98
96
|
preserveTemporaryFile?: boolean
|
|
99
97
|
|
|
100
98
|
/**
|
|
101
|
-
* Provide
|
|
99
|
+
* Provide bundle format explicitly
|
|
102
100
|
* to skip the default format inference
|
|
103
101
|
*/
|
|
104
102
|
format?: 'cjs' | 'esm'
|
|
103
|
+
|
|
105
104
|
}
|
|
106
105
|
```
|
|
107
106
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
3
7
|
|
|
4
|
-
|
|
8
|
+
// ../../node_modules/.pnpm/tsup@8.5.0_@swc+core@1.12.0_jiti@2.4.2_postcss@8.5.4_tsx@4.20.1_typescript@5.8.3_yaml@2.8.0/node_modules/tsup/assets/cjs_shims.js
|
|
9
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
10
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
5
11
|
|
|
6
12
|
// src/index.ts
|
|
7
13
|
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
@@ -23,8 +29,6 @@ var _rolldown = require('rolldown');
|
|
|
23
29
|
// src/utils.ts
|
|
24
30
|
var _child_process = require('child_process');
|
|
25
31
|
var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
|
|
26
|
-
var _dns = require('dns');
|
|
27
|
-
|
|
28
32
|
|
|
29
33
|
|
|
30
34
|
|
|
@@ -34,46 +38,12 @@ var _pluginutils = require('@rollup/pluginutils');
|
|
|
34
38
|
|
|
35
39
|
// src/constants.ts
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
39
41
|
var { version } = JSON.parse(
|
|
40
|
-
_fs.readFileSync.call(void 0, new URL("../package.json",
|
|
41
|
-
);
|
|
42
|
-
var DEFAULT_MAIN_FIELDS = [
|
|
43
|
-
"browser",
|
|
44
|
-
"module",
|
|
45
|
-
"jsnext:main",
|
|
46
|
-
// moment still uses this...
|
|
47
|
-
"jsnext"
|
|
48
|
-
];
|
|
49
|
-
var DEFAULT_CLIENT_MAIN_FIELDS = Object.freeze(DEFAULT_MAIN_FIELDS);
|
|
50
|
-
var DEFAULT_SERVER_MAIN_FIELDS = Object.freeze(
|
|
51
|
-
DEFAULT_MAIN_FIELDS.filter((f) => f !== "browser")
|
|
42
|
+
_fs.readFileSync.call(void 0, new URL("../package.json", importMetaUrl)).toString()
|
|
52
43
|
);
|
|
53
44
|
var DEV_PROD_CONDITION = `development|production`;
|
|
54
|
-
var DEFAULT_CONDITIONS = ["module", "browser", "node", DEV_PROD_CONDITION];
|
|
55
|
-
var DEFAULT_CLIENT_CONDITIONS = Object.freeze(
|
|
56
|
-
DEFAULT_CONDITIONS.filter((c) => c !== "node")
|
|
57
|
-
);
|
|
58
|
-
var DEFAULT_SERVER_CONDITIONS = Object.freeze(
|
|
59
|
-
DEFAULT_CONDITIONS.filter((c) => c !== "browser")
|
|
60
|
-
);
|
|
61
45
|
var OPTIMIZABLE_ENTRY_RE = /\.[cm]?[jt]s$/;
|
|
62
46
|
var SPECIAL_QUERY_RE = /[?&](?:worker|sharedworker|raw|url)\b/;
|
|
63
|
-
var FS_PREFIX = `/@fs/`;
|
|
64
|
-
var CLIENT_PUBLIC_PATH = `/@vite/client`;
|
|
65
|
-
var ENV_PUBLIC_PATH = `/@vite/env`;
|
|
66
|
-
var VITE_PACKAGE_DIR = _path.resolve.call(void 0,
|
|
67
|
-
// import.meta.url is `dist/node/constants.js` after bundle
|
|
68
|
-
_url.fileURLToPath.call(void 0, _chunkQ6XJHTDBcjs.importMetaUrl),
|
|
69
|
-
"../../.."
|
|
70
|
-
);
|
|
71
|
-
var CLIENT_ENTRY = _path.resolve.call(void 0, VITE_PACKAGE_DIR, "dist/client/client.mjs");
|
|
72
|
-
var ENV_ENTRY = _path.resolve.call(void 0, VITE_PACKAGE_DIR, "dist/client/env.mjs");
|
|
73
|
-
var CLIENT_DIR = _path2.default.dirname(CLIENT_ENTRY);
|
|
74
|
-
var VALID_ID_PREFIX = `/@id/`;
|
|
75
|
-
var SOURCEMAPPING_URL = "sourceMa";
|
|
76
|
-
SOURCEMAPPING_URL += "ppingURL";
|
|
77
47
|
|
|
78
48
|
// src/sharedUtils.ts
|
|
79
49
|
|
|
@@ -86,9 +56,9 @@ var postfixRE = /[?#].*$/;
|
|
|
86
56
|
function cleanUrl(url) {
|
|
87
57
|
return url.replace(postfixRE, "");
|
|
88
58
|
}
|
|
89
|
-
function splitFileAndPostfix(
|
|
90
|
-
const file = cleanUrl(
|
|
91
|
-
return { file, postfix:
|
|
59
|
+
function splitFileAndPostfix(path6) {
|
|
60
|
+
const file = cleanUrl(path6);
|
|
61
|
+
return { file, postfix: path6.slice(file.length) };
|
|
92
62
|
}
|
|
93
63
|
var AsyncFunction = async function() {
|
|
94
64
|
}.constructor;
|
|
@@ -143,11 +113,11 @@ function isOptimizable(id, optimizeDeps) {
|
|
|
143
113
|
}
|
|
144
114
|
var bareImportRE = /^(?![a-z]:)[\w@](?!.*:\/\/)/i;
|
|
145
115
|
var deepImportRE = /^([^@][^/]*)\/|^(@[^/]+\/[^/]+)\//;
|
|
146
|
-
var _require = _module.createRequire.call(void 0,
|
|
147
|
-
var _dirname = _path2.default.dirname(_url.fileURLToPath.call(void 0,
|
|
148
|
-
var urlCanParse = _nullishCoalesce(_url.URL.canParse, () => ( ((
|
|
116
|
+
var _require = _module.createRequire.call(void 0, importMetaUrl);
|
|
117
|
+
var _dirname = _path2.default.dirname(_url.fileURLToPath.call(void 0, importMetaUrl));
|
|
118
|
+
var urlCanParse = _nullishCoalesce(_url.URL.canParse, () => ( ((path6, base) => {
|
|
149
119
|
try {
|
|
150
|
-
new (0, _url.URL)(
|
|
120
|
+
new (0, _url.URL)(path6, base);
|
|
151
121
|
return true;
|
|
152
122
|
} catch (e2) {
|
|
153
123
|
return false;
|
|
@@ -156,13 +126,6 @@ var urlCanParse = _nullishCoalesce(_url.URL.canParse, () => ( ((path7, base) =>
|
|
|
156
126
|
function normalizePath(id) {
|
|
157
127
|
return _path2.default.posix.normalize(isWindows ? slash(id) : id);
|
|
158
128
|
}
|
|
159
|
-
var internalPrefixes = [
|
|
160
|
-
FS_PREFIX,
|
|
161
|
-
VALID_ID_PREFIX,
|
|
162
|
-
CLIENT_PUBLIC_PATH,
|
|
163
|
-
ENV_PUBLIC_PATH
|
|
164
|
-
];
|
|
165
|
-
var InternalPrefixRE = new RegExp(`^(?:${internalPrefixes.join("|")})`);
|
|
166
129
|
function injectQuery(url, queryToInject) {
|
|
167
130
|
const { file, postfix } = splitFileAndPostfix(url);
|
|
168
131
|
const normalizedFile = isWindows ? slash(file) : file;
|
|
@@ -196,8 +159,8 @@ function isFilePathESM(filePath, packageCache) {
|
|
|
196
159
|
}
|
|
197
160
|
var safeRealpathSync = isWindows ? windowsSafeRealPathSync : _fs2.default.realpathSync.native;
|
|
198
161
|
var windowsNetworkMap = /* @__PURE__ */ new Map();
|
|
199
|
-
function windowsMappedRealpathSync(
|
|
200
|
-
const realPath = _fs2.default.realpathSync.native(
|
|
162
|
+
function windowsMappedRealpathSync(path6) {
|
|
163
|
+
const realPath = _fs2.default.realpathSync.native(path6);
|
|
201
164
|
if (realPath.startsWith("\\\\")) {
|
|
202
165
|
for (const [network, volume] of windowsNetworkMap) {
|
|
203
166
|
if (realPath.startsWith(network)) {
|
|
@@ -209,12 +172,12 @@ function windowsMappedRealpathSync(path7) {
|
|
|
209
172
|
}
|
|
210
173
|
var parseNetUseRE = /^\w* +(\w:) +([^ ]+)\s/;
|
|
211
174
|
var firstSafeRealPathSyncRun = false;
|
|
212
|
-
function windowsSafeRealPathSync(
|
|
175
|
+
function windowsSafeRealPathSync(path6) {
|
|
213
176
|
if (!firstSafeRealPathSyncRun) {
|
|
214
177
|
optimizeSafeRealPathSync();
|
|
215
178
|
firstSafeRealPathSyncRun = true;
|
|
216
179
|
}
|
|
217
|
-
return _fs2.default.realpathSync(
|
|
180
|
+
return _fs2.default.realpathSync(path6);
|
|
218
181
|
}
|
|
219
182
|
function optimizeSafeRealPathSync() {
|
|
220
183
|
const nodeVersion = _process2.default.versions.node.split(".").map(Number);
|
|
@@ -267,7 +230,7 @@ function getNpmPackageName(importPath) {
|
|
|
267
230
|
}
|
|
268
231
|
}
|
|
269
232
|
var dynamicImport = async (id, { format }) => {
|
|
270
|
-
const fn = format === "esm" ? (file) => Promise.resolve().then(() => _interopRequireWildcard(require(file))) : false ? _module.createRequire.call(void 0,
|
|
233
|
+
const fn = format === "esm" ? (file) => Promise.resolve().then(() => _interopRequireWildcard(require(file))) : false ? _module.createRequire.call(void 0, importMetaUrl) : __require;
|
|
271
234
|
return fn(id);
|
|
272
235
|
};
|
|
273
236
|
|
|
@@ -275,7 +238,7 @@ var dynamicImport = async (id, { format }) => {
|
|
|
275
238
|
var pnp;
|
|
276
239
|
if (_process2.default.versions.pnp) {
|
|
277
240
|
try {
|
|
278
|
-
pnp = _module.createRequire.call(void 0,
|
|
241
|
+
pnp = _module.createRequire.call(void 0, importMetaUrl)("pnpapi");
|
|
279
242
|
} catch (e5) {
|
|
280
243
|
}
|
|
281
244
|
}
|
|
@@ -844,8 +807,8 @@ function mapWithBrowserField(relativePathInPkgDir, map) {
|
|
|
844
807
|
}
|
|
845
808
|
}
|
|
846
809
|
}
|
|
847
|
-
function equalWithoutSuffix(
|
|
848
|
-
return key.endsWith(suffix) && key.slice(0, -suffix.length) ===
|
|
810
|
+
function equalWithoutSuffix(path6, key, suffix) {
|
|
811
|
+
return key.endsWith(suffix) && key.slice(0, -suffix.length) === path6;
|
|
849
812
|
}
|
|
850
813
|
function tryResolveRealFile(file, preserveSymlinks) {
|
|
851
814
|
const stat = tryStatSync(file);
|
|
@@ -876,8 +839,8 @@ function getRealPath(resolved, preserveSymlinks) {
|
|
|
876
839
|
}
|
|
877
840
|
return normalizePath(resolved);
|
|
878
841
|
}
|
|
879
|
-
function isDirectory(
|
|
880
|
-
const stat = tryStatSync(
|
|
842
|
+
function isDirectory(path6) {
|
|
843
|
+
const stat = tryStatSync(path6);
|
|
881
844
|
return _nullishCoalesce(_optionalChain([stat, 'optionalAccess', _36 => _36.isDirectory, 'call', _37 => _37()]), () => ( false));
|
|
882
845
|
}
|
|
883
846
|
|
|
@@ -913,14 +876,14 @@ async function bundleFile(fileName, options) {
|
|
|
913
876
|
const { isESM } = options;
|
|
914
877
|
const isModuleSyncConditionEnabled = (await Promise.resolve().then(() => _interopRequireWildcard(require(
|
|
915
878
|
// @ts-ignore
|
|
916
|
-
"
|
|
879
|
+
"#module-sync-enabled"
|
|
917
880
|
)))).default;
|
|
918
881
|
const dirnameVarName = "__vite_injected_original_dirname";
|
|
919
882
|
const filenameVarName = "__vite_injected_original_filename";
|
|
920
883
|
const importMetaUrlVarName = "__vite_injected_original_import_meta_url";
|
|
921
|
-
const
|
|
884
|
+
const rolldownInputOptions = _optionalChain([options, 'optionalAccess', _38 => _38.rolldownOptions, 'optionalAccess', _39 => _39.input]) || {};
|
|
922
885
|
const bundle = await _rolldown.rolldown.call(void 0, {
|
|
923
|
-
...
|
|
886
|
+
...rolldownInputOptions,
|
|
924
887
|
input: fileName,
|
|
925
888
|
// target: [`node${process.versions.node}`],
|
|
926
889
|
platform: "node",
|
|
@@ -941,7 +904,7 @@ async function bundleFile(fileName, options) {
|
|
|
941
904
|
/* @__PURE__ */ (() => {
|
|
942
905
|
const packageCache = /* @__PURE__ */ new Map();
|
|
943
906
|
const resolveByViteResolver = (id, importer, isRequire) => {
|
|
944
|
-
return _optionalChain([tryNodeResolve, 'call',
|
|
907
|
+
return _optionalChain([tryNodeResolve, 'call', _40 => _40(id, importer, {
|
|
945
908
|
root: _path2.default.dirname(fileName),
|
|
946
909
|
isBuild: true,
|
|
947
910
|
isProduction: true,
|
|
@@ -961,7 +924,7 @@ async function bundleFile(fileName, options) {
|
|
|
961
924
|
packageCache,
|
|
962
925
|
isRequire,
|
|
963
926
|
builtins: nodeLikeBuiltins
|
|
964
|
-
}), 'optionalAccess',
|
|
927
|
+
}), 'optionalAccess', _41 => _41.id]);
|
|
965
928
|
};
|
|
966
929
|
return {
|
|
967
930
|
name: "externalize-deps",
|
|
@@ -1029,12 +992,14 @@ async function bundleFile(fileName, options) {
|
|
|
1029
992
|
external: options.external
|
|
1030
993
|
// preserveEntrySignatures: 'exports-only'
|
|
1031
994
|
});
|
|
995
|
+
const rolldownOutputOptions = _optionalChain([options, 'optionalAccess', _42 => _42.rolldownOptions, 'optionalAccess', _43 => _43.output]) || {};
|
|
1032
996
|
const result = await bundle.generate({
|
|
997
|
+
...rolldownOutputOptions,
|
|
1033
998
|
format: options.format,
|
|
1034
|
-
sourcemap:
|
|
1035
|
-
sourcemapPathTransform(relative) {
|
|
1036
|
-
|
|
1037
|
-
},
|
|
999
|
+
sourcemap: false,
|
|
1000
|
+
// sourcemapPathTransform(relative) {
|
|
1001
|
+
// return path.resolve(fileName, relative)
|
|
1002
|
+
// },
|
|
1038
1003
|
// we want to generate a single chunk like esbuild does with `splitting: false`
|
|
1039
1004
|
inlineDynamicImports: true
|
|
1040
1005
|
});
|
|
@@ -1053,7 +1018,7 @@ async function bundleFile(fileName, options) {
|
|
|
1053
1018
|
dependencies: [...allModules]
|
|
1054
1019
|
};
|
|
1055
1020
|
}
|
|
1056
|
-
var _require2 = _module.createRequire.call(void 0,
|
|
1021
|
+
var _require2 = _module.createRequire.call(void 0, importMetaUrl);
|
|
1057
1022
|
async function loadFromBundledFile(fileName, bundledCode, options) {
|
|
1058
1023
|
const { isESM } = options;
|
|
1059
1024
|
if (isESM) {
|
|
@@ -1088,7 +1053,7 @@ async function loadFromBundledFile(fileName, bundledCode, options) {
|
|
|
1088
1053
|
);
|
|
1089
1054
|
return mod;
|
|
1090
1055
|
} finally {
|
|
1091
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
1056
|
+
if (!_optionalChain([options, 'optionalAccess', _44 => _44.preserveTemporaryFile])) {
|
|
1092
1057
|
_fs2.default.unlink(outfile, () => {
|
|
1093
1058
|
});
|
|
1094
1059
|
}
|
|
@@ -1116,7 +1081,7 @@ async function bundleRequire(options) {
|
|
|
1116
1081
|
const resolvedPath = _path2.default.isAbsolute(options.filepath) ? options.filepath : _path2.default.resolve(options.cwd || _process2.default.cwd(), options.filepath);
|
|
1117
1082
|
const isESM = typeof _process2.default.versions.deno === "string" || isFilePathESM(resolvedPath);
|
|
1118
1083
|
if (options.tsconfig !== false) {
|
|
1119
|
-
options.tsconfig = _nullishCoalesce(_nullishCoalesce(options.tsconfig, () => ( _optionalChain([_gettsconfig.getTsconfig.call(void 0, options.cwd, "tsconfig.json"), 'optionalAccess',
|
|
1084
|
+
options.tsconfig = _nullishCoalesce(_nullishCoalesce(options.tsconfig, () => ( _optionalChain([_gettsconfig.getTsconfig.call(void 0, options.cwd, "tsconfig.json"), 'optionalAccess', _45 => _45.path]))), () => ( void 0));
|
|
1120
1085
|
} else {
|
|
1121
1086
|
options.tsconfig = void 0;
|
|
1122
1087
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InputOptions, ExternalOption } from 'rolldown';
|
|
1
|
+
import { InputOptions, OutputOptions, ExternalOption } from 'rolldown';
|
|
2
2
|
|
|
3
3
|
type RequireFunction = (outfile: string, ctx: {
|
|
4
4
|
format: 'cjs' | 'esm';
|
|
@@ -20,7 +20,10 @@ interface Options {
|
|
|
20
20
|
* esbuild options
|
|
21
21
|
*
|
|
22
22
|
*/
|
|
23
|
-
rolldownOptions?:
|
|
23
|
+
rolldownOptions?: {
|
|
24
|
+
input?: InputOptions;
|
|
25
|
+
output?: OutputOptions;
|
|
26
|
+
};
|
|
24
27
|
/**
|
|
25
28
|
* Get the path to the output file
|
|
26
29
|
* By default we simply replace the extension with `.bundled_{randomId}.js`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InputOptions, ExternalOption } from 'rolldown';
|
|
1
|
+
import { InputOptions, OutputOptions, ExternalOption } from 'rolldown';
|
|
2
2
|
|
|
3
3
|
type RequireFunction = (outfile: string, ctx: {
|
|
4
4
|
format: 'cjs' | 'esm';
|
|
@@ -20,7 +20,10 @@ interface Options {
|
|
|
20
20
|
* esbuild options
|
|
21
21
|
*
|
|
22
22
|
*/
|
|
23
|
-
rolldownOptions?:
|
|
23
|
+
rolldownOptions?: {
|
|
24
|
+
input?: InputOptions;
|
|
25
|
+
output?: OutputOptions;
|
|
26
|
+
};
|
|
24
27
|
/**
|
|
25
28
|
* Get the path to the output file
|
|
26
29
|
* By default we simply replace the extension with `.bundled_{randomId}.js`
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import "./chunk-WUKYLWAZ.mjs";
|
|
2
|
-
|
|
3
1
|
// src/index.ts
|
|
4
2
|
import fs4 from "fs";
|
|
5
|
-
import
|
|
3
|
+
import fsp from "fs/promises";
|
|
6
4
|
import { createRequire as createRequire3 } from "module";
|
|
7
|
-
import
|
|
5
|
+
import path5 from "path";
|
|
8
6
|
import process4 from "process";
|
|
9
7
|
import { pathToFileURL } from "url";
|
|
10
8
|
import { promisify } from "util";
|
|
@@ -14,63 +12,27 @@ import { rolldown } from "rolldown";
|
|
|
14
12
|
// src/packages.ts
|
|
15
13
|
import fs2 from "fs";
|
|
16
14
|
import { createRequire as createRequire2 } from "module";
|
|
17
|
-
import
|
|
15
|
+
import path2 from "path";
|
|
18
16
|
import process3 from "process";
|
|
19
17
|
|
|
20
18
|
// src/utils.ts
|
|
21
19
|
import { exec } from "child_process";
|
|
22
20
|
import crypto from "crypto";
|
|
23
|
-
import { promises as dns } from "dns";
|
|
24
21
|
import fs from "fs";
|
|
25
|
-
import fsp from "fs/promises";
|
|
26
22
|
import { builtinModules, createRequire } from "module";
|
|
27
|
-
import
|
|
23
|
+
import path from "path";
|
|
28
24
|
import process2 from "process";
|
|
29
|
-
import { fileURLToPath
|
|
25
|
+
import { fileURLToPath, URL as URL2 } from "url";
|
|
30
26
|
import { createFilter as _createFilter } from "@rollup/pluginutils";
|
|
31
27
|
|
|
32
28
|
// src/constants.ts
|
|
33
29
|
import { readFileSync } from "fs";
|
|
34
|
-
import path, { resolve } from "path";
|
|
35
|
-
import { fileURLToPath } from "url";
|
|
36
30
|
var { version } = JSON.parse(
|
|
37
31
|
readFileSync(new URL("../package.json", import.meta.url)).toString()
|
|
38
32
|
);
|
|
39
|
-
var DEFAULT_MAIN_FIELDS = [
|
|
40
|
-
"browser",
|
|
41
|
-
"module",
|
|
42
|
-
"jsnext:main",
|
|
43
|
-
// moment still uses this...
|
|
44
|
-
"jsnext"
|
|
45
|
-
];
|
|
46
|
-
var DEFAULT_CLIENT_MAIN_FIELDS = Object.freeze(DEFAULT_MAIN_FIELDS);
|
|
47
|
-
var DEFAULT_SERVER_MAIN_FIELDS = Object.freeze(
|
|
48
|
-
DEFAULT_MAIN_FIELDS.filter((f) => f !== "browser")
|
|
49
|
-
);
|
|
50
33
|
var DEV_PROD_CONDITION = `development|production`;
|
|
51
|
-
var DEFAULT_CONDITIONS = ["module", "browser", "node", DEV_PROD_CONDITION];
|
|
52
|
-
var DEFAULT_CLIENT_CONDITIONS = Object.freeze(
|
|
53
|
-
DEFAULT_CONDITIONS.filter((c) => c !== "node")
|
|
54
|
-
);
|
|
55
|
-
var DEFAULT_SERVER_CONDITIONS = Object.freeze(
|
|
56
|
-
DEFAULT_CONDITIONS.filter((c) => c !== "browser")
|
|
57
|
-
);
|
|
58
34
|
var OPTIMIZABLE_ENTRY_RE = /\.[cm]?[jt]s$/;
|
|
59
35
|
var SPECIAL_QUERY_RE = /[?&](?:worker|sharedworker|raw|url)\b/;
|
|
60
|
-
var FS_PREFIX = `/@fs/`;
|
|
61
|
-
var CLIENT_PUBLIC_PATH = `/@vite/client`;
|
|
62
|
-
var ENV_PUBLIC_PATH = `/@vite/env`;
|
|
63
|
-
var VITE_PACKAGE_DIR = resolve(
|
|
64
|
-
// import.meta.url is `dist/node/constants.js` after bundle
|
|
65
|
-
fileURLToPath(import.meta.url),
|
|
66
|
-
"../../.."
|
|
67
|
-
);
|
|
68
|
-
var CLIENT_ENTRY = resolve(VITE_PACKAGE_DIR, "dist/client/client.mjs");
|
|
69
|
-
var ENV_ENTRY = resolve(VITE_PACKAGE_DIR, "dist/client/env.mjs");
|
|
70
|
-
var CLIENT_DIR = path.dirname(CLIENT_ENTRY);
|
|
71
|
-
var VALID_ID_PREFIX = `/@id/`;
|
|
72
|
-
var SOURCEMAPPING_URL = "sourceMa";
|
|
73
|
-
SOURCEMAPPING_URL += "ppingURL";
|
|
74
36
|
|
|
75
37
|
// src/sharedUtils.ts
|
|
76
38
|
import process from "process";
|
|
@@ -83,9 +45,9 @@ var postfixRE = /[?#].*$/;
|
|
|
83
45
|
function cleanUrl(url) {
|
|
84
46
|
return url.replace(postfixRE, "");
|
|
85
47
|
}
|
|
86
|
-
function splitFileAndPostfix(
|
|
87
|
-
const file = cleanUrl(
|
|
88
|
-
return { file, postfix:
|
|
48
|
+
function splitFileAndPostfix(path6) {
|
|
49
|
+
const file = cleanUrl(path6);
|
|
50
|
+
return { file, postfix: path6.slice(file.length) };
|
|
89
51
|
}
|
|
90
52
|
var AsyncFunction = async function() {
|
|
91
53
|
}.constructor;
|
|
@@ -141,25 +103,18 @@ function isOptimizable(id, optimizeDeps) {
|
|
|
141
103
|
var bareImportRE = /^(?![a-z]:)[\w@](?!.*:\/\/)/i;
|
|
142
104
|
var deepImportRE = /^([^@][^/]*)\/|^(@[^/]+\/[^/]+)\//;
|
|
143
105
|
var _require = createRequire(import.meta.url);
|
|
144
|
-
var _dirname =
|
|
145
|
-
var urlCanParse = URL2.canParse ?? ((
|
|
106
|
+
var _dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
107
|
+
var urlCanParse = URL2.canParse ?? ((path6, base) => {
|
|
146
108
|
try {
|
|
147
|
-
new URL2(
|
|
109
|
+
new URL2(path6, base);
|
|
148
110
|
return true;
|
|
149
111
|
} catch {
|
|
150
112
|
return false;
|
|
151
113
|
}
|
|
152
114
|
});
|
|
153
115
|
function normalizePath(id) {
|
|
154
|
-
return
|
|
116
|
+
return path.posix.normalize(isWindows ? slash(id) : id);
|
|
155
117
|
}
|
|
156
|
-
var internalPrefixes = [
|
|
157
|
-
FS_PREFIX,
|
|
158
|
-
VALID_ID_PREFIX,
|
|
159
|
-
CLIENT_PUBLIC_PATH,
|
|
160
|
-
ENV_PUBLIC_PATH
|
|
161
|
-
];
|
|
162
|
-
var InternalPrefixRE = new RegExp(`^(?:${internalPrefixes.join("|")})`);
|
|
163
118
|
function injectQuery(url, queryToInject) {
|
|
164
119
|
const { file, postfix } = splitFileAndPostfix(url);
|
|
165
120
|
const normalizedFile = isWindows ? slash(file) : file;
|
|
@@ -184,7 +139,7 @@ function isFilePathESM(filePath, packageCache) {
|
|
|
184
139
|
return false;
|
|
185
140
|
} else {
|
|
186
141
|
try {
|
|
187
|
-
const pkg = findNearestPackageData(
|
|
142
|
+
const pkg = findNearestPackageData(path.dirname(filePath), packageCache);
|
|
188
143
|
return pkg?.data.type === "module";
|
|
189
144
|
} catch {
|
|
190
145
|
return false;
|
|
@@ -193,8 +148,8 @@ function isFilePathESM(filePath, packageCache) {
|
|
|
193
148
|
}
|
|
194
149
|
var safeRealpathSync = isWindows ? windowsSafeRealPathSync : fs.realpathSync.native;
|
|
195
150
|
var windowsNetworkMap = /* @__PURE__ */ new Map();
|
|
196
|
-
function windowsMappedRealpathSync(
|
|
197
|
-
const realPath = fs.realpathSync.native(
|
|
151
|
+
function windowsMappedRealpathSync(path6) {
|
|
152
|
+
const realPath = fs.realpathSync.native(path6);
|
|
198
153
|
if (realPath.startsWith("\\\\")) {
|
|
199
154
|
for (const [network, volume] of windowsNetworkMap) {
|
|
200
155
|
if (realPath.startsWith(network)) {
|
|
@@ -206,12 +161,12 @@ function windowsMappedRealpathSync(path7) {
|
|
|
206
161
|
}
|
|
207
162
|
var parseNetUseRE = /^\w* +(\w:) +([^ ]+)\s/;
|
|
208
163
|
var firstSafeRealPathSyncRun = false;
|
|
209
|
-
function windowsSafeRealPathSync(
|
|
164
|
+
function windowsSafeRealPathSync(path6) {
|
|
210
165
|
if (!firstSafeRealPathSyncRun) {
|
|
211
166
|
optimizeSafeRealPathSync();
|
|
212
167
|
firstSafeRealPathSyncRun = true;
|
|
213
168
|
}
|
|
214
|
-
return fs.realpathSync(
|
|
169
|
+
return fs.realpathSync(path6);
|
|
215
170
|
}
|
|
216
171
|
function optimizeSafeRealPathSync() {
|
|
217
172
|
const nodeVersion = process2.versions.node.split(".").map(Number);
|
|
@@ -220,7 +175,7 @@ function optimizeSafeRealPathSync() {
|
|
|
220
175
|
return;
|
|
221
176
|
}
|
|
222
177
|
try {
|
|
223
|
-
fs.realpathSync.native(
|
|
178
|
+
fs.realpathSync.native(path.resolve("./"));
|
|
224
179
|
} catch (error) {
|
|
225
180
|
if (error.message.includes("EISDIR: illegal operation on a directory")) {
|
|
226
181
|
safeRealpathSync = fs.realpathSync;
|
|
@@ -289,7 +244,7 @@ function resolvePackageData(pkgName, basedir, preserveSymlinks = false, packageC
|
|
|
289
244
|
if (!pkg) {
|
|
290
245
|
return null;
|
|
291
246
|
}
|
|
292
|
-
const pkgData = loadPackageData(
|
|
247
|
+
const pkgData = loadPackageData(path2.join(pkg, "package.json"));
|
|
293
248
|
packageCache?.set(cacheKey, pkgData);
|
|
294
249
|
return pkgData;
|
|
295
250
|
} catch {
|
|
@@ -310,7 +265,7 @@ function resolvePackageData(pkgName, basedir, preserveSymlinks = false, packageC
|
|
|
310
265
|
return cached;
|
|
311
266
|
}
|
|
312
267
|
}
|
|
313
|
-
const pkg =
|
|
268
|
+
const pkg = path2.join(basedir, "node_modules", pkgName, "package.json");
|
|
314
269
|
try {
|
|
315
270
|
if (fs2.existsSync(pkg)) {
|
|
316
271
|
const pkgPath = preserveSymlinks ? pkg : safeRealpathSync(pkg);
|
|
@@ -329,7 +284,7 @@ function resolvePackageData(pkgName, basedir, preserveSymlinks = false, packageC
|
|
|
329
284
|
}
|
|
330
285
|
} catch {
|
|
331
286
|
}
|
|
332
|
-
const nextBasedir =
|
|
287
|
+
const nextBasedir = path2.dirname(basedir);
|
|
333
288
|
if (nextBasedir === basedir) {
|
|
334
289
|
break;
|
|
335
290
|
}
|
|
@@ -346,7 +301,7 @@ function findNearestPackageData(basedir, packageCache) {
|
|
|
346
301
|
return cached;
|
|
347
302
|
}
|
|
348
303
|
}
|
|
349
|
-
const pkgPath =
|
|
304
|
+
const pkgPath = path2.join(basedir, "package.json");
|
|
350
305
|
if (tryStatSync(pkgPath)?.isFile()) {
|
|
351
306
|
try {
|
|
352
307
|
const pkgData = loadPackageData(pkgPath);
|
|
@@ -357,7 +312,7 @@ function findNearestPackageData(basedir, packageCache) {
|
|
|
357
312
|
} catch {
|
|
358
313
|
}
|
|
359
314
|
}
|
|
360
|
-
const nextBasedir =
|
|
315
|
+
const nextBasedir = path2.dirname(basedir);
|
|
361
316
|
if (nextBasedir === basedir) {
|
|
362
317
|
break;
|
|
363
318
|
}
|
|
@@ -368,13 +323,13 @@ function findNearestPackageData(basedir, packageCache) {
|
|
|
368
323
|
function findNearestMainPackageData(basedir, packageCache) {
|
|
369
324
|
const nearestPackage = findNearestPackageData(basedir, packageCache);
|
|
370
325
|
return nearestPackage && (nearestPackage.data.name ? nearestPackage : findNearestMainPackageData(
|
|
371
|
-
|
|
326
|
+
path2.dirname(nearestPackage.dir),
|
|
372
327
|
packageCache
|
|
373
328
|
));
|
|
374
329
|
}
|
|
375
330
|
function loadPackageData(pkgPath) {
|
|
376
331
|
const data = JSON.parse(stripBomTag(fs2.readFileSync(pkgPath, "utf-8")));
|
|
377
|
-
const pkgDir = normalizePath(
|
|
332
|
+
const pkgDir = normalizePath(path2.dirname(pkgPath));
|
|
378
333
|
const { sideEffects } = data;
|
|
379
334
|
let hasSideEffects;
|
|
380
335
|
if (typeof sideEffects === "boolean") {
|
|
@@ -421,11 +376,11 @@ function getResolveCacheKey(key, options) {
|
|
|
421
376
|
}
|
|
422
377
|
function findNearestNodeModules(basedir) {
|
|
423
378
|
while (basedir) {
|
|
424
|
-
const pkgPath =
|
|
379
|
+
const pkgPath = path2.join(basedir, "node_modules");
|
|
425
380
|
if (tryStatSync(pkgPath)?.isDirectory()) {
|
|
426
381
|
return pkgPath;
|
|
427
382
|
}
|
|
428
|
-
const nextBasedir =
|
|
383
|
+
const nextBasedir = path2.dirname(basedir);
|
|
429
384
|
if (nextBasedir === basedir) {
|
|
430
385
|
break;
|
|
431
386
|
}
|
|
@@ -474,20 +429,20 @@ function getFnpdCacheKey(basedir) {
|
|
|
474
429
|
function traverseBetweenDirs(longerDir, shorterDir, cb) {
|
|
475
430
|
while (longerDir !== shorterDir) {
|
|
476
431
|
cb(longerDir);
|
|
477
|
-
longerDir =
|
|
432
|
+
longerDir = path2.dirname(longerDir);
|
|
478
433
|
}
|
|
479
434
|
}
|
|
480
435
|
|
|
481
436
|
// src/plugins/resolve.ts
|
|
482
437
|
import fs3 from "fs";
|
|
483
|
-
import
|
|
438
|
+
import path4 from "path";
|
|
484
439
|
import { hasESMSyntax } from "mlly";
|
|
485
440
|
import { exports, imports } from "resolve.exports";
|
|
486
441
|
|
|
487
442
|
// src/external.ts
|
|
488
|
-
import
|
|
443
|
+
import path3 from "path";
|
|
489
444
|
function canExternalizeFile(filePath) {
|
|
490
|
-
const ext =
|
|
445
|
+
const ext = path3.extname(filePath);
|
|
491
446
|
return !ext || ext === ".js" || ext === ".mjs" || ext === ".cjs";
|
|
492
447
|
}
|
|
493
448
|
|
|
@@ -524,10 +479,10 @@ function tryCleanFsResolve(file, options, tryIndex = true, skipPackageJson = fal
|
|
|
524
479
|
let res;
|
|
525
480
|
const possibleJsToTs = isPossibleTsOutput(file);
|
|
526
481
|
if (possibleJsToTs || options.extensions.length || tryPrefix) {
|
|
527
|
-
const dirPath =
|
|
482
|
+
const dirPath = path4.dirname(file);
|
|
528
483
|
if (isDirectory(dirPath)) {
|
|
529
484
|
if (possibleJsToTs) {
|
|
530
|
-
const fileExt =
|
|
485
|
+
const fileExt = path4.extname(file);
|
|
531
486
|
const fileName = file.slice(0, -fileExt.length);
|
|
532
487
|
if (res = tryResolveRealFile(
|
|
533
488
|
fileName + fileExt.replace("js", "ts"),
|
|
@@ -547,7 +502,7 @@ function tryCleanFsResolve(file, options, tryIndex = true, skipPackageJson = fal
|
|
|
547
502
|
return res;
|
|
548
503
|
}
|
|
549
504
|
if (tryPrefix) {
|
|
550
|
-
const prefixed = `${dirPath}/${options.tryPrefix}${
|
|
505
|
+
const prefixed = `${dirPath}/${options.tryPrefix}${path4.basename(file)}`;
|
|
551
506
|
if (res = tryResolveRealFile(prefixed, preserveSymlinks)) {
|
|
552
507
|
return res;
|
|
553
508
|
}
|
|
@@ -604,8 +559,8 @@ function tryNodeResolve(id, importer, options, depsOptimizer, externalize) {
|
|
|
604
559
|
let basedir;
|
|
605
560
|
if (dedupe.includes(pkgId)) {
|
|
606
561
|
basedir = root;
|
|
607
|
-
} else if (importer &&
|
|
608
|
-
basedir =
|
|
562
|
+
} else if (importer && path4.isAbsolute(importer) && (importer.endsWith("*") || fs3.existsSync(cleanUrl(importer)))) {
|
|
563
|
+
basedir = path4.dirname(importer);
|
|
609
564
|
} else {
|
|
610
565
|
basedir = root;
|
|
611
566
|
}
|
|
@@ -644,7 +599,7 @@ function tryNodeResolve(id, importer, options, depsOptimizer, externalize) {
|
|
|
644
599
|
return resolved2;
|
|
645
600
|
}
|
|
646
601
|
let resolvedId = id;
|
|
647
|
-
if (deepMatch && !pkg.data.exports &&
|
|
602
|
+
if (deepMatch && !pkg.data.exports && path4.extname(id) !== path4.extname(resolved2.id)) {
|
|
648
603
|
const index = resolved2.id.indexOf(id);
|
|
649
604
|
if (index > -1) {
|
|
650
605
|
resolvedId = resolved2.id.slice(index);
|
|
@@ -703,7 +658,7 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
|
|
|
703
658
|
const entryPoints = entryPoint ? [entryPoint] : ["index.js", "index.json", "index.node"];
|
|
704
659
|
for (let entry of entryPoints) {
|
|
705
660
|
let skipPackageJson = false;
|
|
706
|
-
if (options.mainFields[0] === "sass" && !options.extensions.includes(
|
|
661
|
+
if (options.mainFields[0] === "sass" && !options.extensions.includes(path4.extname(entry))) {
|
|
707
662
|
entry = "";
|
|
708
663
|
skipPackageJson = true;
|
|
709
664
|
} else {
|
|
@@ -712,7 +667,7 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
|
|
|
712
667
|
entry = mapWithBrowserField(entry, browserField) || entry;
|
|
713
668
|
}
|
|
714
669
|
}
|
|
715
|
-
const entryPointPath =
|
|
670
|
+
const entryPointPath = path4.join(dir, entry);
|
|
716
671
|
const resolvedEntryPoint = tryFsResolve(
|
|
717
672
|
entryPointPath,
|
|
718
673
|
options,
|
|
@@ -785,7 +740,7 @@ function resolveDeepImport(id, { setResolvedCache, getResolvedCache, dir, data }
|
|
|
785
740
|
}
|
|
786
741
|
if (!relativeId) {
|
|
787
742
|
throw new Error(
|
|
788
|
-
`Package subpath '${relativeId}' is not defined by "exports" in ${
|
|
743
|
+
`Package subpath '${relativeId}' is not defined by "exports" in ${path4.join(dir, "package.json")}.`
|
|
789
744
|
);
|
|
790
745
|
}
|
|
791
746
|
} else if (options.mainFields.includes("browser") && isObject(browserField)) {
|
|
@@ -800,7 +755,7 @@ function resolveDeepImport(id, { setResolvedCache, getResolvedCache, dir, data }
|
|
|
800
755
|
}
|
|
801
756
|
if (relativeId) {
|
|
802
757
|
const resolved = tryFsResolve(
|
|
803
|
-
|
|
758
|
+
path4.join(dir, relativeId),
|
|
804
759
|
options,
|
|
805
760
|
!exportsField
|
|
806
761
|
// try index only if no exports field
|
|
@@ -816,7 +771,7 @@ function tryResolveBrowserEntry(dir, data, options) {
|
|
|
816
771
|
if (browserEntry) {
|
|
817
772
|
if (!options.isRequire && options.mainFields.includes("module") && typeof data.module === "string" && data.module !== browserEntry) {
|
|
818
773
|
const resolvedBrowserEntry = tryFsResolve(
|
|
819
|
-
|
|
774
|
+
path4.join(dir, browserEntry),
|
|
820
775
|
options
|
|
821
776
|
);
|
|
822
777
|
if (resolvedBrowserEntry) {
|
|
@@ -833,16 +788,16 @@ function tryResolveBrowserEntry(dir, data, options) {
|
|
|
833
788
|
}
|
|
834
789
|
}
|
|
835
790
|
function mapWithBrowserField(relativePathInPkgDir, map) {
|
|
836
|
-
const normalizedPath =
|
|
791
|
+
const normalizedPath = path4.posix.normalize(relativePathInPkgDir);
|
|
837
792
|
for (const key in map) {
|
|
838
|
-
const normalizedKey =
|
|
793
|
+
const normalizedKey = path4.posix.normalize(key);
|
|
839
794
|
if (normalizedPath === normalizedKey || equalWithoutSuffix(normalizedPath, normalizedKey, ".js") || equalWithoutSuffix(normalizedPath, normalizedKey, "/index.js")) {
|
|
840
795
|
return map[key];
|
|
841
796
|
}
|
|
842
797
|
}
|
|
843
798
|
}
|
|
844
|
-
function equalWithoutSuffix(
|
|
845
|
-
return key.endsWith(suffix) && key.slice(0, -suffix.length) ===
|
|
799
|
+
function equalWithoutSuffix(path6, key, suffix) {
|
|
800
|
+
return key.endsWith(suffix) && key.slice(0, -suffix.length) === path6;
|
|
846
801
|
}
|
|
847
802
|
function tryResolveRealFile(file, preserveSymlinks) {
|
|
848
803
|
const stat = tryStatSync(file);
|
|
@@ -873,8 +828,8 @@ function getRealPath(resolved, preserveSymlinks) {
|
|
|
873
828
|
}
|
|
874
829
|
return normalizePath(resolved);
|
|
875
830
|
}
|
|
876
|
-
function isDirectory(
|
|
877
|
-
const stat = tryStatSync(
|
|
831
|
+
function isDirectory(path6) {
|
|
832
|
+
const stat = tryStatSync(path6);
|
|
878
833
|
return stat?.isDirectory() ?? false;
|
|
879
834
|
}
|
|
880
835
|
|
|
@@ -910,14 +865,14 @@ async function bundleFile(fileName, options) {
|
|
|
910
865
|
const { isESM } = options;
|
|
911
866
|
const isModuleSyncConditionEnabled = (await import(
|
|
912
867
|
// @ts-ignore
|
|
913
|
-
"
|
|
868
|
+
"#module-sync-enabled"
|
|
914
869
|
)).default;
|
|
915
870
|
const dirnameVarName = "__vite_injected_original_dirname";
|
|
916
871
|
const filenameVarName = "__vite_injected_original_filename";
|
|
917
872
|
const importMetaUrlVarName = "__vite_injected_original_import_meta_url";
|
|
918
|
-
const
|
|
873
|
+
const rolldownInputOptions = options?.rolldownOptions?.input || {};
|
|
919
874
|
const bundle = await rolldown({
|
|
920
|
-
...
|
|
875
|
+
...rolldownInputOptions,
|
|
921
876
|
input: fileName,
|
|
922
877
|
// target: [`node${process.versions.node}`],
|
|
923
878
|
platform: "node",
|
|
@@ -939,7 +894,7 @@ async function bundleFile(fileName, options) {
|
|
|
939
894
|
const packageCache = /* @__PURE__ */ new Map();
|
|
940
895
|
const resolveByViteResolver = (id, importer, isRequire) => {
|
|
941
896
|
return tryNodeResolve(id, importer, {
|
|
942
|
-
root:
|
|
897
|
+
root: path5.dirname(fileName),
|
|
943
898
|
isBuild: true,
|
|
944
899
|
isProduction: true,
|
|
945
900
|
preferRelative: false,
|
|
@@ -965,7 +920,7 @@ async function bundleFile(fileName, options) {
|
|
|
965
920
|
resolveId: {
|
|
966
921
|
filter: { id: /^[^.#].*/ },
|
|
967
922
|
async handler(id, importer, { kind }) {
|
|
968
|
-
if (!importer ||
|
|
923
|
+
if (!importer || path5.isAbsolute(id) || isNodeBuiltin(id)) {
|
|
969
924
|
return;
|
|
970
925
|
}
|
|
971
926
|
if (isNodeLikeBuiltin(id)) {
|
|
@@ -1015,7 +970,7 @@ async function bundleFile(fileName, options) {
|
|
|
1015
970
|
transform: {
|
|
1016
971
|
filter: { id: /\.[cm]?[jt]s$/ },
|
|
1017
972
|
async handler(code, id) {
|
|
1018
|
-
const injectValues = `const ${dirnameVarName} = ${JSON.stringify(
|
|
973
|
+
const injectValues = `const ${dirnameVarName} = ${JSON.stringify(path5.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify(
|
|
1019
974
|
pathToFileURL(id).href
|
|
1020
975
|
)};`;
|
|
1021
976
|
return { code: injectValues + code, map: null };
|
|
@@ -1026,12 +981,14 @@ async function bundleFile(fileName, options) {
|
|
|
1026
981
|
external: options.external
|
|
1027
982
|
// preserveEntrySignatures: 'exports-only'
|
|
1028
983
|
});
|
|
984
|
+
const rolldownOutputOptions = options?.rolldownOptions?.output || {};
|
|
1029
985
|
const result = await bundle.generate({
|
|
986
|
+
...rolldownOutputOptions,
|
|
1030
987
|
format: options.format,
|
|
1031
|
-
sourcemap:
|
|
1032
|
-
sourcemapPathTransform(relative) {
|
|
1033
|
-
|
|
1034
|
-
},
|
|
988
|
+
sourcemap: false,
|
|
989
|
+
// sourcemapPathTransform(relative) {
|
|
990
|
+
// return path.resolve(fileName, relative)
|
|
991
|
+
// },
|
|
1035
992
|
// we want to generate a single chunk like esbuild does with `splitting: false`
|
|
1036
993
|
inlineDynamicImports: true
|
|
1037
994
|
});
|
|
@@ -1054,10 +1011,10 @@ var _require2 = createRequire3(import.meta.url);
|
|
|
1054
1011
|
async function loadFromBundledFile(fileName, bundledCode, options) {
|
|
1055
1012
|
const { isESM } = options;
|
|
1056
1013
|
if (isESM) {
|
|
1057
|
-
let nodeModulesDir = typeof process4.versions.deno === "string" ? void 0 : findNearestNodeModules(
|
|
1014
|
+
let nodeModulesDir = typeof process4.versions.deno === "string" ? void 0 : findNearestNodeModules(path5.dirname(fileName));
|
|
1058
1015
|
if (nodeModulesDir) {
|
|
1059
1016
|
try {
|
|
1060
|
-
await
|
|
1017
|
+
await fsp.mkdir(path5.resolve(nodeModulesDir, ".vite-temp/"), {
|
|
1061
1018
|
recursive: true
|
|
1062
1019
|
});
|
|
1063
1020
|
} catch (e) {
|
|
@@ -1069,13 +1026,13 @@ async function loadFromBundledFile(fileName, bundledCode, options) {
|
|
|
1069
1026
|
}
|
|
1070
1027
|
}
|
|
1071
1028
|
const hash2 = `timestamp-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
1072
|
-
const tempFileName = nodeModulesDir ?
|
|
1029
|
+
const tempFileName = nodeModulesDir ? path5.resolve(
|
|
1073
1030
|
nodeModulesDir,
|
|
1074
|
-
`.vite-temp/${
|
|
1031
|
+
`.vite-temp/${path5.basename(fileName)}.${hash2}.${isESM ? "mjs" : "cjs"}`
|
|
1075
1032
|
) : `${fileName}.${hash2}.mjs`;
|
|
1076
1033
|
const getOutputFile = options.getOutputFile || defaultGetOutputFile;
|
|
1077
1034
|
const outfile = getOutputFile(tempFileName, options.format);
|
|
1078
|
-
await
|
|
1035
|
+
await fsp.writeFile(outfile, bundledCode);
|
|
1079
1036
|
let mod;
|
|
1080
1037
|
const req = options.require || dynamicImport;
|
|
1081
1038
|
try {
|
|
@@ -1091,7 +1048,7 @@ async function loadFromBundledFile(fileName, bundledCode, options) {
|
|
|
1091
1048
|
}
|
|
1092
1049
|
}
|
|
1093
1050
|
} else {
|
|
1094
|
-
const extension =
|
|
1051
|
+
const extension = path5.extname(fileName);
|
|
1095
1052
|
const realFileName = await promisifiedRealpath(fileName);
|
|
1096
1053
|
const loaderExt = extension in _require2.extensions ? extension : ".js";
|
|
1097
1054
|
const defaultLoader = _require2.extensions[loaderExt];
|
|
@@ -1110,7 +1067,7 @@ async function loadFromBundledFile(fileName, bundledCode, options) {
|
|
|
1110
1067
|
}
|
|
1111
1068
|
}
|
|
1112
1069
|
async function bundleRequire(options) {
|
|
1113
|
-
const resolvedPath =
|
|
1070
|
+
const resolvedPath = path5.isAbsolute(options.filepath) ? options.filepath : path5.resolve(options.cwd || process4.cwd(), options.filepath);
|
|
1114
1071
|
const isESM = typeof process4.versions.deno === "string" || isFilePathESM(resolvedPath);
|
|
1115
1072
|
if (options.tsconfig !== false) {
|
|
1116
1073
|
options.tsconfig = options.tsconfig ?? getTsconfig(options.cwd, "tsconfig.json")?.path ?? void 0;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-require",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"description": "bundle and require a file using rolldown!",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -13,8 +13,17 @@
|
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://github.com/weapp-vite/weapp-vite/issues"
|
|
15
15
|
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
|
|
16
|
+
"keywords": [
|
|
17
|
+
"require",
|
|
18
|
+
"rolldown",
|
|
19
|
+
"runtime",
|
|
20
|
+
"node",
|
|
21
|
+
"cjs",
|
|
22
|
+
"commonjs",
|
|
23
|
+
"esm",
|
|
24
|
+
"typescript",
|
|
25
|
+
"bundle"
|
|
26
|
+
],
|
|
18
27
|
"imports": {
|
|
19
28
|
"#module-sync-enabled": {
|
|
20
29
|
"module-sync": "./misc/true.js",
|
package/dist/chunk-Q6XJHTDB.cjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
// ../../node_modules/.pnpm/tsup@8.5.0_@swc+core@1.12.0_jiti@2.4.2_postcss@8.5.4_tsx@4.20.1_typescript@5.8.3_yaml@2.8.0/node_modules/tsup/assets/cjs_shims.js
|
|
9
|
-
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
10
|
-
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
exports.__require = __require; exports.importMetaUrl = importMetaUrl;
|
package/dist/chunk-WUKYLWAZ.mjs
DELETED
|
File without changes
|
package/dist/false-G5OFYI37.mjs
DELETED
package/dist/false-SI6OY5LO.cjs
DELETED