rolldown-require 1.0.1 → 1.0.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/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
- * Defaults to the global `require` function.
69
- * This function can be asynchronous and return a Promise.
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?: InputOptions
71
+ rolldownOptions?: {
72
+ input?: InputOptions
73
+ output?: OutputOptions
74
+ }
75
+
77
76
  /**
78
77
  * Get the path to the output file
79
- * By default, we simply replace the extension with `.bundled_{randomId}.js`
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 the `paths` option
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 the compiled temporary file for debugging
98
- * Defaults to `process.env.BUNDLE_REQUIRE_PRESERVE`
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 the bundle format explicitly
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
@@ -5,7 +5,7 @@
5
5
  throw Error('Dynamic require of "' + x + '" is not supported');
6
6
  });
7
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
8
+ // ../../node_modules/.pnpm/tsup@8.5.0_@swc+core@1.13.4_jiti@2.5.1_postcss@8.5.6_tsx@4.20.5_typescript@5.9.2_yaml@2.8.1/node_modules/tsup/assets/cjs_shims.js
9
9
  var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
10
10
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
11
11
 
@@ -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 rolldownOptions = _optionalChain([options, 'optionalAccess', _38 => _38.rolldownOptions]) || {};
884
+ const rolldownInputOptions = _optionalChain([options, 'optionalAccess', _38 => _38.rolldownOptions, 'optionalAccess', _39 => _39.input]) || {};
885
885
  const bundle = await _rolldown.rolldown.call(void 0, {
886
- ...rolldownOptions,
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', _39 => _39(id, importer, {
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', _40 => _40.id]);
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: "inline",
998
- sourcemapPathTransform(relative) {
999
- return _path2.default.resolve(fileName, relative);
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', _41 => _41.preserveTemporaryFile])) {
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', _42 => _42.path]))), () => ( void 0));
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?: InputOptions;
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?: InputOptions;
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 rolldownOptions = options?.rolldownOptions || {};
873
+ const rolldownInputOptions = options?.rolldownOptions?.input || {};
874
874
  const bundle = await rolldown({
875
- ...rolldownOptions,
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: "inline",
987
- sourcemapPathTransform(relative) {
988
- return path5.resolve(fileName, relative);
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
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rolldown-require",
3
3
  "type": "module",
4
- "version": "1.0.1",
4
+ "version": "1.0.3",
5
5
  "description": "bundle and require a file using rolldown!",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -48,12 +48,12 @@
48
48
  "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "rolldown": "*"
51
+ "rolldown": ">=1.0.0-beta.33"
52
52
  },
53
53
  "dependencies": {
54
- "@rollup/pluginutils": "^5.1.4",
54
+ "@rollup/pluginutils": "^5.2.0",
55
55
  "get-tsconfig": "^4.10.1",
56
- "mlly": "^1.7.4",
56
+ "mlly": "^1.8.0",
57
57
  "resolve.exports": "^2.0.3"
58
58
  },
59
59
  "devDependencies": {