@visulima/packem-rollup 1.0.0-alpha.24 → 1.0.0-alpha.25
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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## @visulima/packem-rollup [1.0.0-alpha.25](https://github.com/visulima/packem/compare/@visulima/packem-rollup@1.0.0-alpha.24...@visulima/packem-rollup@1.0.0-alpha.25) (2025-10-28)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* enhance require-cjs-transformer with multi-entry point support ([6f0a824](https://github.com/visulima/packem/commit/6f0a824fe982bc9dc18e0e19fd9de55754ac37b3))
|
|
6
|
+
|
|
1
7
|
## @visulima/packem-rollup [1.0.0-alpha.24](https://github.com/visulima/packem/compare/@visulima/packem-rollup@1.0.0-alpha.23...@visulima/packem-rollup@1.0.0-alpha.24) (2025-10-28)
|
|
2
8
|
|
|
3
9
|
### Bug Fixes
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { FilterPattern } from '@rollup/pluginutils';
|
|
2
|
-
import { Plugin } from 'rollup';
|
|
2
|
+
import { ResolvedId, Plugin } from 'rollup';
|
|
3
3
|
|
|
4
4
|
type Awaitable<T> = T | Promise<T>;
|
|
5
|
-
type TransformFunction = (id: string, importer: string, rollupResolve: (id: string, importer?: string) => Promise<
|
|
6
|
-
id: string;
|
|
7
|
-
}>) => Awaitable<boolean | undefined | void>;
|
|
5
|
+
type TransformFunction = (id: string, importer: string, rollupResolve: ((id: string, importer?: string) => Promise<ResolvedId | null>)) => Awaitable<boolean | undefined | void>;
|
|
8
6
|
interface Options {
|
|
9
7
|
builtinNodeModules?: boolean;
|
|
10
8
|
cwd?: string;
|
|
@@ -13,7 +11,7 @@ interface Options {
|
|
|
13
11
|
order?: "pre" | "post" | undefined;
|
|
14
12
|
shouldTransform?: string[] | TransformFunction;
|
|
15
13
|
}
|
|
16
|
-
declare const requireCJSTransformerPlugin: (userOptions: Options,
|
|
14
|
+
declare const requireCJSTransformerPlugin: (userOptions: Options, _logger: Console) => Plugin;
|
|
17
15
|
|
|
18
16
|
export { requireCJSTransformerPlugin };
|
|
19
17
|
export type { Options, TransformFunction };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var E=Object.defineProperty;var w=(e,r)=>E(e,"name",{value:r,configurable:!0});import{createRequire as F,builtinModules as K}from"node:module";import B from"node:process";import{createFilter as L}from"@rollup/pluginutils";import{init as x,parse as G}from"cjs-module-lexer";import S from"magic-string";import{parseSync as H}from"oxc-parser";import{readFile as Q}from"@visulima/fs";import{findPackageJson as U}from"@visulima/package/package-json";var V=Object.defineProperty,X=w((e,r)=>V(e,"name",{value:r,configurable:!0}),"s");const Y=X(async(e,r,i)=>{if(await x(),e.startsWith("node:"))return!1;if(e.endsWith(".cjs"))return!0;if(e.endsWith(".js")||!e.includes("/")&&!e.startsWith(".")){let s;if(i)try{s=(await i(e,r)).id}catch{}if(!s&&r&&!r.includes("!~{"))try{s=F(r).resolve(e)}catch{}if(s){try{const{packageJson:o}=await U(s);if(o.type==="module")return!1;if(o.type==="commonjs")return!0}catch{}try{const o=await Q(s,{encoding:"utf8"});try{return G(o,s),!0}catch{}}catch{}}}return!1},"isPureCJS");var Z=Object.defineProperty,m=w((e,r)=>Z(e,"name",{value:r,configurable:!0}),"c");const T="__cjs_require",z='import { createRequire as __cjs_createRequire } from "node:module";',ee=`const ${T} = __cjs_createRequire(import.meta.url);`,re='const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;',se=`const __cjs_getBuiltinModule = (module) => {
|
|
2
2
|
// Check if we're in Node.js and version supports getBuiltinModule
|
|
3
3
|
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
4
4
|
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
@@ -8,18 +8,14 @@ var H=Object.defineProperty;var b=(e,i)=>H(e,"name",{value:i,configurable:!0});i
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
// Fallback to createRequire
|
|
11
|
-
return
|
|
12
|
-
};`,
|
|
13
|
-
|
|
11
|
+
return ${T}(module);
|
|
12
|
+
};`,g={builtin:/const\s+__cjs_getBuiltinModule\s*=\s*\(module\)\s*=>\s*\{[\s\S]*?\};\s*/g,import:/import\s*\{\s*createRequire(?:\s+as\s+__cjs_createRequire)?\s*\}\s*from\s*["']node:module["'];?\s*/g,process:/const\s+__cjs_getProcess\s*=\s*typeof\s+globalThis[^;]*;\s*/g,require:/const\s+__cjs_require\s*=\s*(?:__cjs_)?createRequire\s*\([^)]*\);\s*/g};let R=!1;const te=m((e,r)=>r&&(K.includes(e)||e.startsWith("node:")),"isBuiltinModule"),oe=m(async(e,r,i,s,o)=>{if(r)return!0;const c=await i?.(e,s,o);return c===void 0?await Y(e,s,o):c},"shouldTransformImport"),ne=m((e,r)=>r?e==="process"||e==="node:process"?{code:"__cjs_getProcess",needsBuiltin:!1,needsProcess:!0,needsRequire:!0}:{code:`__cjs_getBuiltinModule(${JSON.stringify(e)})`,needsBuiltin:!0,needsProcess:!0,needsRequire:!0}:{code:`${T}(${JSON.stringify(e)})`,needsBuiltin:!1,needsProcess:!1,needsRequire:!0},"generateRequireCode"),ie=m(e=>{const r=new S(e),i={builtin:[...e.matchAll(g.builtin)],import:[...e.matchAll(g.import)],process:[...e.matchAll(g.process)],require:[...e.matchAll(g.require)]};return Object.values(i).forEach(s=>{if(s.length>1)for(let o=s.length-1;o>0;o-=1){const c=s[o];c&&r.remove(c.index,c.index+c[0].length)}}),r.toString()},"removeDuplicates"),ce=m(e=>{if(Array.isArray(e.shouldTransform)){const{shouldTransform:r}=e;e.shouldTransform=i=>r.includes(i)}return{builtinNodeModules:!!e.builtinNodeModules,cwd:e.cwd||B.cwd(),exclude:e.exclude||[/node_modules/,/\.d\.[cm]?ts$/],include:e.include||[/\.[cm]?[jt]sx?$/],order:"order"in e?e.order:"pre",shouldTransform:e.shouldTransform}},"resolveOptions"),he=m((e,r)=>{if(B.env.INTERNAL_PACKEM_BUILD)return{name:"require-cjs-transformer"};const{builtinNodeModules:i,cwd:s,exclude:o,include:c,order:A,shouldTransform:C}=ce(e),J=L(c,o);return{async buildStart(){R||(await x(),R=!0)},name:"packem:plugin-require-cjs",renderChunk:{async handler(h,M,O){if(O.format!=="es"||!J(M.fileName))return;const I=H(M.fileName,h,{astType:"js",lang:"js",sourceType:"module"}),u=new S(h);let j=!1,y=!1,v=!1;for await(const t of I.program.body){if(t.type!=="ImportDeclaration"||t.importKind==="type")continue;const l=t.source.value,d=te(l,i),$=this.resolve;if(!await oe(l,d,C,s,$))continue;const{code:b,needsBuiltin:k,needsProcess:W,needsRequire:D}=ne(l,d);if(j||=D,y||=W,v||=k,t.specifiers.length===0){d?u.remove(t.start,t.end):u.overwrite(t.start,t.end,`${b};`);continue}const P=[];let f,a;for(const n of t.specifiers)if(n.type==="ImportNamespaceSpecifier")f=n.local.name;else if(n.type==="ImportSpecifier"&&n.importKind!=="type"){const _=h.slice(n.imported.start,n.imported.end);P.push([_,n.local.name])}else n.type==="ImportDefaultSpecifier"&&(a=n.local.name);const p=[];if(f&&(a||=`_cjs_${f}_default`),a&&p.push(`const ${a} = ${b};`),f&&p.push(`const ${f} = { ...${a}, default: ${a} };`),P.length>0){const n=`const {
|
|
13
|
+
${P.map(([_,q])=>` ${_===q?q:`${_}: ${q}`}`).join(`,
|
|
14
14
|
`)}
|
|
15
|
+
} = ${a||b};`;p.push(n)}u.overwrite(t.start,t.end,p.join(`
|
|
16
|
+
`))}if(j||y||v){const t=[];j&&t.push(z,ee),y&&t.push(re),v&&t.push(se);const l=`${t.join(`
|
|
15
17
|
|
|
16
|
-
`;if(s[0]==="#"){const m=s.indexOf(`
|
|
17
|
-
`)+1;r.appendLeft(m,l)}else r.prepend(l);return i.debug({message:`Added complete helpers to chunk: ${y.fileName}, added ${n.length} helper(s)`,prefix:"plugin:require-cjs-transformer"}),{code:r.toString(),map:r.generateMap()}}}if(!F(y.fileName))return;const G=X(y.fileName,t,{astType:"js",lang:"js",sourceType:"module"}),{body:L}=G.program,a=new B(t);let p=!1,P=!1,N=!1;for await(const s of L)if(s.type==="ImportDeclaration"){if(s.importKind==="type")continue;const r=s.source.value,n=_&&(Z.includes(r)||r.startsWith("node:"));let l;if(n)l=!0;else{const o=D?.(r,c,this?.resolveId);l=o===void 0?await ie(r,c,this.resolveId?.bind(this)):o}if(!l)continue;if(s.specifiers.length===0){n?a.remove(s.start,s.end):(a.overwrite(s.start,s.end,`${v}(${JSON.stringify(r)});`),p=!0);continue}const m=[];let g,d;for(const o of s.specifiers)if(o.type==="ImportNamespaceSpecifier")g=o.local.name;else if(o.type==="ImportSpecifier"){if(o.importKind==="type")continue;const $=t.slice(o.imported.start,o.imported.end),h=o.local.name;m.push([$,h])}else d=o.local.name;let j;n?r==="process"||r==="node:process"?(j="__cjs_getProcess",P=!0,p=!0):(j=`__cjs_getBuiltinModule(${JSON.stringify(r)})`,P=!0,N=!0,p=!0):(j=`__cjs_require(${JSON.stringify(r)})`,p=!0);const q=[];if(g&&(d||=`_cjs_${g}_default`),d&&q.push(`const ${d} = ${j};`),g&&q.push(`const ${g} = { ...${d}, default: ${d} };`),m.length>0){const o=`const {
|
|
18
|
-
${m.map(([$,h])=>` ${$===h?h:`${$}: ${h}`}`).join(`,
|
|
19
18
|
`)}
|
|
20
|
-
} = ${d||j};`;q.push(o)}const E=q.join(`
|
|
21
|
-
`);a.overwrite(s.start,s.end,E)}const K=t.includes("__cjs_require")||t.includes("__cjs_getProcess")||t.includes("__cjs_getBuiltinModule");if(p||K){const s=[];(p||t.includes("__cjs_require"))&&(C(t)||s.push(S),O(t)||s.push(x)),(P||t.includes("__cjs_getProcess"))&&!ne(t)&&s.push(J),(N||t.includes("__cjs_getBuiltinModule"))&&!ce(t)&&s.push(k);const r=s.join(`
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
`)+1;a.appendLeft(n,r)}else a.prepend(r)}return{code:a.toString(),map:a.generateMap()}},order:A}}},"requireCJSTransformerPlugin");export{$e as requireCJSTransformerPlugin};
|
|
20
|
+
`,d=u.toString();if(d[0]==="#"){const $=d.indexOf(`
|
|
21
|
+
`)+1;u.appendLeft($,l)}else u.prepend(l)}const N=new S(ie(u.toString()));return{code:N.toString(),map:N.generateMap()}},order:A}}},"requireCJSTransformerPlugin");export{he as requireCJSTransformerPlugin};
|