rolldown-require 1.0.1 → 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 +17 -20
- package/dist/index.cjs +12 -10
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.mjs +8 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,6 +43,8 @@ const { mod } = await bundleRequire({
|
|
|
43
43
|
## Options
|
|
44
44
|
|
|
45
45
|
```ts
|
|
46
|
+
import type { ExternalOption, InputOptions, OutputOptions } from 'rolldown'
|
|
47
|
+
|
|
46
48
|
export type RequireFunction = (
|
|
47
49
|
outfile: string,
|
|
48
50
|
ctx: { format: 'cjs' | 'esm' },
|
|
@@ -50,13 +52,6 @@ export type RequireFunction = (
|
|
|
50
52
|
|
|
51
53
|
export type GetOutputFile = (filepath: string, format: 'esm' | 'cjs') => string
|
|
52
54
|
|
|
53
|
-
export type RebuildCallback = (
|
|
54
|
-
error: RollupError | null,
|
|
55
|
-
result: RolldownOutput | null,
|
|
56
|
-
) => void
|
|
57
|
-
|
|
58
|
-
export type ReadFile = (filepath: string) => string
|
|
59
|
-
|
|
60
55
|
export interface Options {
|
|
61
56
|
cwd?: string
|
|
62
57
|
/**
|
|
@@ -64,46 +59,48 @@ export interface Options {
|
|
|
64
59
|
*/
|
|
65
60
|
filepath: string
|
|
66
61
|
/**
|
|
67
|
-
* The `require` function used to load the output file
|
|
68
|
-
*
|
|
69
|
-
* 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
|
|
70
65
|
*/
|
|
71
66
|
require?: RequireFunction
|
|
72
67
|
/**
|
|
73
68
|
* esbuild options
|
|
74
69
|
*
|
|
75
70
|
*/
|
|
76
|
-
rolldownOptions?:
|
|
71
|
+
rolldownOptions?: {
|
|
72
|
+
input?: InputOptions
|
|
73
|
+
output?: OutputOptions
|
|
74
|
+
}
|
|
75
|
+
|
|
77
76
|
/**
|
|
78
77
|
* Get the path to the output file
|
|
79
|
-
* By default
|
|
78
|
+
* By default we simply replace the extension with `.bundled_{randomId}.js`
|
|
80
79
|
*/
|
|
81
80
|
getOutputFile?: GetOutputFile
|
|
82
|
-
/**
|
|
83
|
-
* Enable watching and call the callback after each rebuild
|
|
84
|
-
*/
|
|
85
81
|
|
|
86
82
|
/** External packages */
|
|
87
83
|
external?: ExternalOption
|
|
88
84
|
|
|
89
85
|
/**
|
|
90
|
-
* A custom tsconfig path to read
|
|
86
|
+
* A custom tsconfig path to read `paths` option
|
|
91
87
|
*
|
|
92
|
-
* Set to `false` to disable tsconfig
|
|
88
|
+
* Set to `false` to disable tsconfig
|
|
93
89
|
*/
|
|
94
90
|
tsconfig?: string | false
|
|
95
91
|
|
|
96
92
|
/**
|
|
97
|
-
* Preserve
|
|
98
|
-
*
|
|
93
|
+
* Preserve compiled temporary file for debugging
|
|
94
|
+
* Default to `process.env.BUNDLE_REQUIRE_PRESERVE`
|
|
99
95
|
*/
|
|
100
96
|
preserveTemporaryFile?: boolean
|
|
101
97
|
|
|
102
98
|
/**
|
|
103
|
-
* Provide
|
|
99
|
+
* Provide bundle format explicitly
|
|
104
100
|
* to skip the default format inference
|
|
105
101
|
*/
|
|
106
102
|
format?: 'cjs' | 'esm'
|
|
103
|
+
|
|
107
104
|
}
|
|
108
105
|
```
|
|
109
106
|
|
package/dist/index.cjs
CHANGED
|
@@ -881,9 +881,9 @@ async function bundleFile(fileName, options) {
|
|
|
881
881
|
const dirnameVarName = "__vite_injected_original_dirname";
|
|
882
882
|
const filenameVarName = "__vite_injected_original_filename";
|
|
883
883
|
const importMetaUrlVarName = "__vite_injected_original_import_meta_url";
|
|
884
|
-
const
|
|
884
|
+
const rolldownInputOptions = _optionalChain([options, 'optionalAccess', _38 => _38.rolldownOptions, 'optionalAccess', _39 => _39.input]) || {};
|
|
885
885
|
const bundle = await _rolldown.rolldown.call(void 0, {
|
|
886
|
-
...
|
|
886
|
+
...rolldownInputOptions,
|
|
887
887
|
input: fileName,
|
|
888
888
|
// target: [`node${process.versions.node}`],
|
|
889
889
|
platform: "node",
|
|
@@ -904,7 +904,7 @@ async function bundleFile(fileName, options) {
|
|
|
904
904
|
/* @__PURE__ */ (() => {
|
|
905
905
|
const packageCache = /* @__PURE__ */ new Map();
|
|
906
906
|
const resolveByViteResolver = (id, importer, isRequire) => {
|
|
907
|
-
return _optionalChain([tryNodeResolve, 'call',
|
|
907
|
+
return _optionalChain([tryNodeResolve, 'call', _40 => _40(id, importer, {
|
|
908
908
|
root: _path2.default.dirname(fileName),
|
|
909
909
|
isBuild: true,
|
|
910
910
|
isProduction: true,
|
|
@@ -924,7 +924,7 @@ async function bundleFile(fileName, options) {
|
|
|
924
924
|
packageCache,
|
|
925
925
|
isRequire,
|
|
926
926
|
builtins: nodeLikeBuiltins
|
|
927
|
-
}), 'optionalAccess',
|
|
927
|
+
}), 'optionalAccess', _41 => _41.id]);
|
|
928
928
|
};
|
|
929
929
|
return {
|
|
930
930
|
name: "externalize-deps",
|
|
@@ -992,12 +992,14 @@ async function bundleFile(fileName, options) {
|
|
|
992
992
|
external: options.external
|
|
993
993
|
// preserveEntrySignatures: 'exports-only'
|
|
994
994
|
});
|
|
995
|
+
const rolldownOutputOptions = _optionalChain([options, 'optionalAccess', _42 => _42.rolldownOptions, 'optionalAccess', _43 => _43.output]) || {};
|
|
995
996
|
const result = await bundle.generate({
|
|
997
|
+
...rolldownOutputOptions,
|
|
996
998
|
format: options.format,
|
|
997
|
-
sourcemap:
|
|
998
|
-
sourcemapPathTransform(relative) {
|
|
999
|
-
|
|
1000
|
-
},
|
|
999
|
+
sourcemap: false,
|
|
1000
|
+
// sourcemapPathTransform(relative) {
|
|
1001
|
+
// return path.resolve(fileName, relative)
|
|
1002
|
+
// },
|
|
1001
1003
|
// we want to generate a single chunk like esbuild does with `splitting: false`
|
|
1002
1004
|
inlineDynamicImports: true
|
|
1003
1005
|
});
|
|
@@ -1051,7 +1053,7 @@ async function loadFromBundledFile(fileName, bundledCode, options) {
|
|
|
1051
1053
|
);
|
|
1052
1054
|
return mod;
|
|
1053
1055
|
} finally {
|
|
1054
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
1056
|
+
if (!_optionalChain([options, 'optionalAccess', _44 => _44.preserveTemporaryFile])) {
|
|
1055
1057
|
_fs2.default.unlink(outfile, () => {
|
|
1056
1058
|
});
|
|
1057
1059
|
}
|
|
@@ -1079,7 +1081,7 @@ async function bundleRequire(options) {
|
|
|
1079
1081
|
const resolvedPath = _path2.default.isAbsolute(options.filepath) ? options.filepath : _path2.default.resolve(options.cwd || _process2.default.cwd(), options.filepath);
|
|
1080
1082
|
const isESM = typeof _process2.default.versions.deno === "string" || isFilePathESM(resolvedPath);
|
|
1081
1083
|
if (options.tsconfig !== false) {
|
|
1082
|
-
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));
|
|
1083
1085
|
} else {
|
|
1084
1086
|
options.tsconfig = void 0;
|
|
1085
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
|
@@ -870,9 +870,9 @@ async function bundleFile(fileName, options) {
|
|
|
870
870
|
const dirnameVarName = "__vite_injected_original_dirname";
|
|
871
871
|
const filenameVarName = "__vite_injected_original_filename";
|
|
872
872
|
const importMetaUrlVarName = "__vite_injected_original_import_meta_url";
|
|
873
|
-
const
|
|
873
|
+
const rolldownInputOptions = options?.rolldownOptions?.input || {};
|
|
874
874
|
const bundle = await rolldown({
|
|
875
|
-
...
|
|
875
|
+
...rolldownInputOptions,
|
|
876
876
|
input: fileName,
|
|
877
877
|
// target: [`node${process.versions.node}`],
|
|
878
878
|
platform: "node",
|
|
@@ -981,12 +981,14 @@ async function bundleFile(fileName, options) {
|
|
|
981
981
|
external: options.external
|
|
982
982
|
// preserveEntrySignatures: 'exports-only'
|
|
983
983
|
});
|
|
984
|
+
const rolldownOutputOptions = options?.rolldownOptions?.output || {};
|
|
984
985
|
const result = await bundle.generate({
|
|
986
|
+
...rolldownOutputOptions,
|
|
985
987
|
format: options.format,
|
|
986
|
-
sourcemap:
|
|
987
|
-
sourcemapPathTransform(relative) {
|
|
988
|
-
|
|
989
|
-
},
|
|
988
|
+
sourcemap: false,
|
|
989
|
+
// sourcemapPathTransform(relative) {
|
|
990
|
+
// return path.resolve(fileName, relative)
|
|
991
|
+
// },
|
|
990
992
|
// we want to generate a single chunk like esbuild does with `splitting: false`
|
|
991
993
|
inlineDynamicImports: true
|
|
992
994
|
});
|