@rspack/cli 2.0.0-rc.1 → 2.0.0-rc.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/compiled/jiti/dist/babel.cjs +246 -0
- package/compiled/jiti/dist/jiti.cjs +1 -0
- package/compiled/jiti/index.d.ts +388 -0
- package/compiled/jiti/index.js +30 -0
- package/compiled/jiti/license +21 -0
- package/compiled/jiti/package.json +1 -0
- package/dist/{697.js → 162.js} +78 -184
- package/dist/constants.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/json-ext.js +6 -2
- package/dist/utils/loadConfig.d.ts +2 -2
- package/dist/utils/options.d.ts +2 -1
- package/package.json +7 -6
- package/dist/utils/crossImport.d.ts +0 -1
- package/dist/utils/isEsmFile.d.ts +0 -1
- package/dist/utils/readPackageUp.d.ts +0 -4
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new {@linkcode Jiti} instance with custom options.
|
|
3
|
+
*
|
|
4
|
+
* @param id - Instance id, usually the current filename.
|
|
5
|
+
* @param userOptions - Custom options to override the default options.
|
|
6
|
+
* @returns A {@linkcode Jiti} instance.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* <caption>ESM Usage</caption>
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { createJiti } from "jiti";
|
|
13
|
+
*
|
|
14
|
+
* const jiti = createJiti(import.meta.url, { debug: true });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* <caption>CommonJS Usage **(deprecated)**</caption>
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* const { createJiti } = require("jiti");
|
|
22
|
+
*
|
|
23
|
+
* const jiti = createJiti(__filename, { debug: true });
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @since 2.0.0
|
|
27
|
+
*/
|
|
28
|
+
declare function createJiti(id: string, userOptions?: JitiOptions): Jiti;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Jiti instance
|
|
32
|
+
*
|
|
33
|
+
* Calling `jiti()` is similar to CommonJS {@linkcode require()} but adds
|
|
34
|
+
* extra features such as TypeScript and ESM compatibility.
|
|
35
|
+
*
|
|
36
|
+
* **Note:** It is recommended to use
|
|
37
|
+
* {@linkcode Jiti.import | await jiti.import()} instead.
|
|
38
|
+
*/
|
|
39
|
+
interface Jiti extends NodeRequire {
|
|
40
|
+
/**
|
|
41
|
+
* Resolved options
|
|
42
|
+
*/
|
|
43
|
+
options: JitiOptions;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* ESM import a module with additional TypeScript and ESM compatibility.
|
|
47
|
+
*
|
|
48
|
+
* If you need the default export of module, you can use
|
|
49
|
+
* `jiti.import(id, { default: true })` as shortcut to `mod?.default ?? mod`.
|
|
50
|
+
*/
|
|
51
|
+
import<T = unknown>(
|
|
52
|
+
id: string,
|
|
53
|
+
opts?: JitiResolveOptions & { default?: true },
|
|
54
|
+
): Promise<T>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Resolve with ESM import conditions.
|
|
58
|
+
*/
|
|
59
|
+
esmResolve(id: string, parentURL?: string): string;
|
|
60
|
+
esmResolve<T extends JitiResolveOptions = JitiResolveOptions>(
|
|
61
|
+
id: string,
|
|
62
|
+
opts?: T,
|
|
63
|
+
): T["try"] extends true ? string | undefined : string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Transform source code
|
|
67
|
+
*/
|
|
68
|
+
transform: (opts: TransformOptions) => string;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Evaluate transformed code as a module
|
|
72
|
+
*/
|
|
73
|
+
evalModule: (source: string, options?: EvalModuleOptions) => unknown;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Jiti instance options
|
|
78
|
+
*/
|
|
79
|
+
interface JitiOptions {
|
|
80
|
+
/**
|
|
81
|
+
* Filesystem source cache
|
|
82
|
+
*
|
|
83
|
+
* An string can be passed to set the custom cache directory.
|
|
84
|
+
*
|
|
85
|
+
* By default (when set to `true`), jiti uses
|
|
86
|
+
* `node_modules/.cache/jiti` (if exists) or `{TMP_DIR}/jiti`.
|
|
87
|
+
*
|
|
88
|
+
* This option can also be disabled using
|
|
89
|
+
* `JITI_FS_CACHE=false` environment variable.
|
|
90
|
+
*
|
|
91
|
+
* **Note:** It is recommended to keep this option
|
|
92
|
+
* enabled for better performance.
|
|
93
|
+
*
|
|
94
|
+
* @default true
|
|
95
|
+
*/
|
|
96
|
+
fsCache?: boolean | string;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Rebuild the filesystem source cache
|
|
100
|
+
*
|
|
101
|
+
* This option can also be enabled using
|
|
102
|
+
* `JITI_REBUILD_FS_CACHE=true` environment variable.
|
|
103
|
+
*
|
|
104
|
+
* @default false
|
|
105
|
+
*/
|
|
106
|
+
rebuildFsCache?: boolean;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @deprecated Use the {@linkcode fsCache} option.
|
|
110
|
+
*
|
|
111
|
+
* @default true
|
|
112
|
+
*/
|
|
113
|
+
cache?: boolean | string;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Runtime module cache
|
|
117
|
+
*
|
|
118
|
+
* Disabling allows editing code and importing same module multiple times.
|
|
119
|
+
*
|
|
120
|
+
* When enabled, jiti integrates with Node.js native CommonJS cache store.
|
|
121
|
+
*
|
|
122
|
+
* This option can also be disabled using
|
|
123
|
+
* `JITI_MODULE_CACHE=false` environment variable.
|
|
124
|
+
*
|
|
125
|
+
* @default true
|
|
126
|
+
*/
|
|
127
|
+
moduleCache?: boolean;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @deprecated Use the {@linkcode moduleCache} option.
|
|
131
|
+
*
|
|
132
|
+
* @default true
|
|
133
|
+
*/
|
|
134
|
+
requireCache?: boolean;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Custom transform function
|
|
138
|
+
*/
|
|
139
|
+
transform?: (opts: TransformOptions) => TransformResult;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Enable verbose debugging.
|
|
143
|
+
*
|
|
144
|
+
* Can also be enabled using `JITI_DEBUG=1` environment variable.
|
|
145
|
+
*
|
|
146
|
+
* @default false
|
|
147
|
+
*/
|
|
148
|
+
debug?: boolean;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Enable sourcemaps for transformed code.
|
|
152
|
+
*
|
|
153
|
+
* Can also be disabled using `JITI_SOURCE_MAPS=0` environment variable.
|
|
154
|
+
*
|
|
155
|
+
* @default false
|
|
156
|
+
*/
|
|
157
|
+
sourceMaps?: boolean;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Jiti combines module exports with the `default` export using an
|
|
161
|
+
* internal Proxy to improve compatibility with mixed CJS/ESM usage.
|
|
162
|
+
* You can check the current implementation
|
|
163
|
+
* {@link https://github.com/unjs/jiti/blob/main/src/utils.ts#L105 here}.
|
|
164
|
+
*
|
|
165
|
+
* Can be disabled using `JITI_INTEROP_DEFAULT=0` environment variable.
|
|
166
|
+
*
|
|
167
|
+
* @default true
|
|
168
|
+
*/
|
|
169
|
+
interopDefault?: boolean;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Jiti hard source cache version.
|
|
173
|
+
*
|
|
174
|
+
* @internal
|
|
175
|
+
*/
|
|
176
|
+
cacheVersion?: string;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Supported extensions to resolve.
|
|
180
|
+
*
|
|
181
|
+
* @default [".js", ".mjs", ".cjs", ".ts", ".tsx", ".mts", ".cts", ".mtsx", ".ctsx", ".json"]
|
|
182
|
+
*/
|
|
183
|
+
extensions?: string[];
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Transform options
|
|
187
|
+
*/
|
|
188
|
+
transformOptions?: Omit<TransformOptions, "source">;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Resolve aliases
|
|
192
|
+
*
|
|
193
|
+
* You can use `JITI_ALIAS` environment variable to set aliases as
|
|
194
|
+
* a JSON string.
|
|
195
|
+
*
|
|
196
|
+
* @default {}
|
|
197
|
+
*/
|
|
198
|
+
alias?: Record<string, string>;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* List of modules (within `node_modules`) to always use native
|
|
202
|
+
* require/import for them.
|
|
203
|
+
*
|
|
204
|
+
* You can use `JITI_NATIVE_MODULES` environment variable to set
|
|
205
|
+
* native modules as a JSON string.
|
|
206
|
+
*
|
|
207
|
+
* @default []
|
|
208
|
+
*/
|
|
209
|
+
nativeModules?: string[];
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* List of modules (within `node_modules`) to transform them
|
|
213
|
+
* regardless of syntax.
|
|
214
|
+
*
|
|
215
|
+
* You can use `JITI_TRANSFORM_MODULES` environment variable to set
|
|
216
|
+
* transform modules as a JSON string.
|
|
217
|
+
*
|
|
218
|
+
* @default []
|
|
219
|
+
*/
|
|
220
|
+
transformModules?: string[];
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Parent module's {@linkcode ImportMeta | import.meta} context to use
|
|
224
|
+
* for ESM resolution.
|
|
225
|
+
*
|
|
226
|
+
* (Only used for `jiti/native` import)
|
|
227
|
+
*/
|
|
228
|
+
importMeta?: ImportMeta;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Try to use native require and import without jiti transformations first.
|
|
232
|
+
*
|
|
233
|
+
* Enabled if Bun is detected.
|
|
234
|
+
*
|
|
235
|
+
* @default false
|
|
236
|
+
*/
|
|
237
|
+
tryNative?: boolean;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Enable JSX support Enable JSX support using
|
|
241
|
+
* {@link https://babeljs.io/docs/babel-plugin-transform-react-jsx | `@babel/plugin-transform-react-jsx`}.
|
|
242
|
+
*
|
|
243
|
+
* You can also use `JITI_JSX=1` environment variable to enable JSX support.
|
|
244
|
+
*
|
|
245
|
+
* @default false
|
|
246
|
+
*/
|
|
247
|
+
jsx?: boolean | JSXOptions;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
interface NodeRequire {
|
|
251
|
+
/**
|
|
252
|
+
* Module cache
|
|
253
|
+
*/
|
|
254
|
+
cache: ModuleCache;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* @deprecated Prefer {@linkcode Jiti.import | await jiti.import()}
|
|
258
|
+
* for better compatibility.
|
|
259
|
+
*/
|
|
260
|
+
(id: string): any;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @deprecated Prefer {@linkcode Jiti.esmResolve | jiti.esmResolve}
|
|
264
|
+
* for better compatibility.
|
|
265
|
+
*/
|
|
266
|
+
resolve: {
|
|
267
|
+
/** @deprecated */
|
|
268
|
+
(id: string, options?: { paths?: string[] | undefined }): string;
|
|
269
|
+
/** @deprecated */
|
|
270
|
+
paths(request: string): string[] | null;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
/** @deprecated CommonJS API */
|
|
274
|
+
extensions: Record<
|
|
275
|
+
".js" | ".json" | ".node",
|
|
276
|
+
(m: NodeModule, filename: string) => any | undefined
|
|
277
|
+
>;
|
|
278
|
+
|
|
279
|
+
/** @deprecated CommonJS API */
|
|
280
|
+
main: NodeModule | undefined;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
interface NodeModule {
|
|
284
|
+
/**
|
|
285
|
+
* `true` if the module is running during the Node.js preload.
|
|
286
|
+
*/
|
|
287
|
+
isPreloading: boolean;
|
|
288
|
+
exports: any;
|
|
289
|
+
require: NodeRequire;
|
|
290
|
+
id: string;
|
|
291
|
+
filename: string;
|
|
292
|
+
loaded: boolean;
|
|
293
|
+
/**
|
|
294
|
+
* @deprecated since Node.js **v14.6.0** Please use
|
|
295
|
+
* {@linkcode NodeRequire.main | require.main} and
|
|
296
|
+
* {@linkcode NodeModule.children | module.children} instead.
|
|
297
|
+
*/
|
|
298
|
+
parent: NodeModule | null | undefined;
|
|
299
|
+
children: NodeModule[];
|
|
300
|
+
/**
|
|
301
|
+
* The directory name of the module.
|
|
302
|
+
* This is usually the same as the `path.dirname()` of the `module.id`.
|
|
303
|
+
*
|
|
304
|
+
* @since Node.js **v11.14.0**
|
|
305
|
+
*/
|
|
306
|
+
path: string;
|
|
307
|
+
paths: string[];
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
type ModuleCache = Record<string, NodeModule>;
|
|
311
|
+
|
|
312
|
+
type EvalModuleOptions = Partial<{
|
|
313
|
+
id: string;
|
|
314
|
+
filename: string;
|
|
315
|
+
ext: string;
|
|
316
|
+
cache: ModuleCache;
|
|
317
|
+
/**
|
|
318
|
+
* @default true
|
|
319
|
+
*/
|
|
320
|
+
async: boolean;
|
|
321
|
+
forceTranspile: boolean;
|
|
322
|
+
}>;
|
|
323
|
+
|
|
324
|
+
interface TransformOptions {
|
|
325
|
+
source: string;
|
|
326
|
+
filename?: string;
|
|
327
|
+
ts?: boolean;
|
|
328
|
+
retainLines?: boolean;
|
|
329
|
+
interopDefault?: boolean;
|
|
330
|
+
/**
|
|
331
|
+
* @default false
|
|
332
|
+
*/
|
|
333
|
+
async?: boolean;
|
|
334
|
+
/**
|
|
335
|
+
* @default false
|
|
336
|
+
*/
|
|
337
|
+
jsx?: boolean | JSXOptions;
|
|
338
|
+
babel?: Record<string, any>;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
interface TransformResult {
|
|
342
|
+
code: string;
|
|
343
|
+
error?: any;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
interface JitiResolveOptions {
|
|
347
|
+
conditions?: string[];
|
|
348
|
+
parentURL?: string | URL;
|
|
349
|
+
try?: boolean;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* @see {@link https://babeljs.io/docs/babel-plugin-transform-react-jsx#options | Reference}
|
|
354
|
+
*/
|
|
355
|
+
interface JSXOptions {
|
|
356
|
+
throwIfNamespace?: boolean;
|
|
357
|
+
runtime?: "classic" | "automatic";
|
|
358
|
+
importSource?: string;
|
|
359
|
+
pragma?: string;
|
|
360
|
+
pragmaFrag?: string;
|
|
361
|
+
useBuiltIns?: boolean;
|
|
362
|
+
useSpread?: boolean;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
type types_EvalModuleOptions = EvalModuleOptions;
|
|
366
|
+
type types_JSXOptions = JSXOptions;
|
|
367
|
+
type types_Jiti = Jiti;
|
|
368
|
+
type types_JitiOptions = JitiOptions;
|
|
369
|
+
type types_JitiResolveOptions = JitiResolveOptions;
|
|
370
|
+
type types_ModuleCache = ModuleCache;
|
|
371
|
+
type types_NodeModule = NodeModule;
|
|
372
|
+
type types_NodeRequire = NodeRequire;
|
|
373
|
+
type types_TransformOptions = TransformOptions;
|
|
374
|
+
type types_TransformResult = TransformResult;
|
|
375
|
+
declare const types_createJiti: typeof createJiti;
|
|
376
|
+
declare namespace types {
|
|
377
|
+
export { types_createJiti as createJiti };
|
|
378
|
+
export type { types_EvalModuleOptions as EvalModuleOptions, types_JSXOptions as JSXOptions, types_Jiti as Jiti, types_JitiOptions as JitiOptions, types_JitiResolveOptions as JitiResolveOptions, types_ModuleCache as ModuleCache, types_NodeModule as NodeModule, types_NodeRequire as NodeRequire, types_TransformOptions as TransformOptions, types_TransformResult as TransformResult };
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
declare const allExports: typeof types & {
|
|
382
|
+
/**
|
|
383
|
+
* @deprecated Please use `const { createJiti } = require("jiti")` or use ESM import.
|
|
384
|
+
*/
|
|
385
|
+
(...args: Parameters<typeof createJiti>): Jiti;
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
export { allExports as default };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { createRequire } = require("node:module");
|
|
2
|
+
const _createJiti = require("./dist/jiti.cjs");
|
|
3
|
+
|
|
4
|
+
function onError(err) {
|
|
5
|
+
throw err;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const nativeImport = (id) => import(id);
|
|
9
|
+
|
|
10
|
+
let _transform;
|
|
11
|
+
function lazyTransform(...args) {
|
|
12
|
+
if (!_transform) {
|
|
13
|
+
_transform = require("./dist/babel.cjs");
|
|
14
|
+
}
|
|
15
|
+
return _transform(...args);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function createJiti(id, opts = {}) {
|
|
19
|
+
if (!opts.transform) {
|
|
20
|
+
opts = { ...opts, transform: lazyTransform };
|
|
21
|
+
}
|
|
22
|
+
return _createJiti(id, opts, {
|
|
23
|
+
onError,
|
|
24
|
+
nativeImport,
|
|
25
|
+
createRequire,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = createJiti;
|
|
30
|
+
module.exports.createJiti = createJiti;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Pooya Parsa <pooya@pi0.io>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"jiti","version":"2.6.1","license":"MIT","types":"index.d.ts","type":"commonjs"}
|