rolldown-plugin-require-cjs 0.1.0 → 0.1.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/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Plugin } from "rolldown";
3
3
  //#region src/options.d.ts
4
4
  type FilterPattern = Array<string | RegExp> | string | RegExp;
5
5
  type Awaitable<T> = T | Promise<T>;
6
+ type TransformFn = (id: string, importer: string) => Awaitable<boolean | undefined | void>;
6
7
  interface Options {
7
8
  include?: FilterPattern;
8
9
  exclude?: FilterPattern;
@@ -16,14 +17,16 @@ interface Options {
16
17
  * @param importer The module ID (path) of the importer.
17
18
  * @returns A boolean or a promise that resolves to a boolean, or `undefined`.
18
19
  */
19
- shouldTransform?: (id: string, importer: string) => Awaitable<boolean | undefined | void>;
20
+ shouldTransform?: string[] | TransformFn;
20
21
  }
21
22
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
22
- type OptionsResolved = Overwrite<Required<Options>, Pick<Options, "order" | "shouldTransform">>;
23
+ type OptionsResolved = Overwrite<Required<Options>, Pick<Options, "order"> & {
24
+ shouldTransform?: TransformFn;
25
+ }>;
23
26
  declare function resolveOptions(options: Options): OptionsResolved;
24
27
  //#endregion
25
28
  //#region src/index.d.ts
26
29
  declare function RequireCJS(userOptions?: Options): Plugin;
27
30
  declare function isPureCJS(id: string, importer: string): Promise<boolean>;
28
31
  //#endregion
29
- export { Options, OptionsResolved, RequireCJS, isPureCJS, resolveOptions };
32
+ export { Options, OptionsResolved, RequireCJS, TransformFn, isPureCJS, resolveOptions };
package/dist/index.js CHANGED
@@ -10862,6 +10862,10 @@ function parseAst(sourceText, options, filename) {
10862
10862
  //#endregion
10863
10863
  //#region src/options.ts
10864
10864
  function resolveOptions(options) {
10865
+ if (Array.isArray(options.shouldTransform)) {
10866
+ const { shouldTransform } = options;
10867
+ options.shouldTransform = (id) => shouldTransform.includes(id);
10868
+ }
10865
10869
  return {
10866
10870
  include: options.include || [/\.[cm]?[jt]sx?$/],
10867
10871
  exclude: options.exclude || [/node_modules/, /\.d\.[cm]?ts$/],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-require-cjs",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Transform ESM imports to CJS requires when the imported module is pure CJS.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -59,6 +59,6 @@
59
59
  "test": "vitest",
60
60
  "typecheck": "tsc --noEmit",
61
61
  "format": "prettier --cache --write .",
62
- "release": "bumpp && unotp pnpm publish"
62
+ "release": "bumpp"
63
63
  }
64
64
  }