@visulima/packem-rollup 1.0.0-alpha.24 → 1.0.0-alpha.26
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,19 @@
|
|
|
1
|
+
## @visulima/packem-rollup [1.0.0-alpha.26](https://github.com/visulima/packem/compare/@visulima/packem-rollup@1.0.0-alpha.25...@visulima/packem-rollup@1.0.0-alpha.26) (2025-11-08)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* add unbundle mode to preserve source file structure ([317e992](https://github.com/visulima/packem/commit/317e9925eae1344a2459f044250e717241a1d5a5))
|
|
6
|
+
|
|
7
|
+
### Miscellaneous Chores
|
|
8
|
+
|
|
9
|
+
* update package.json and pnpm-lock.yaml for dependency management ([aa523ca](https://github.com/visulima/packem/commit/aa523ca16f29ba0a874a13693d1f9581acf6f8c3))
|
|
10
|
+
|
|
11
|
+
## @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)
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* enhance require-cjs-transformer with multi-entry point support ([6f0a824](https://github.com/visulima/packem/commit/6f0a824fe982bc9dc18e0e19fd9de55754ac37b3))
|
|
16
|
+
|
|
1
17
|
## @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
18
|
|
|
3
19
|
### Bug Fixes
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
//# sourceMappingURL=${
|
|
3
|
-
`,"appendMapUrl"),
|
|
1
|
+
var G=Object.defineProperty;var $=(t,e)=>G(t,"name",{value:e,configurable:!0});import{createFilter as U}from"@rollup/pluginutils";import{readFile as _}from"@visulima/fs";import{ENDING_REGEX as E}from"@visulima/packem-share/constants";import{getDtsExtension as C}from"@visulima/packem-share/utils";import{dirname as S,toNamespacedPath as w,sep as F,extname as J,isAbsolute as L,relative as R,join as k,basename as O}from"@visulima/path";import{parseAsync as X}from"oxc-parser";import{_ as q}from"../../packem_shared/fix-dts-default-cjs-exports-BQc0nwIG.js";var z=Object.defineProperty,B=$((t,e)=>z(t,"name",{value:e,configurable:!0}),"e");const A=/^([\w-]+):/,P=B(t=>{if(!t||typeof t!="string")throw new Error("Invalid key: Key must be a non-empty string.");const e=[],c=A.exec(t);c&&(e.push(c[1]),t=t.replace(A,""));const n=t.split("/");for(const l of n)(l.includes("*")||l)&&e.push(l);return e},"splitTsconfigPathKey");var H=Object.defineProperty,Q=$((t,e)=>H(t,"name",{value:e,configurable:!0}),"h");const V=Q((t,e)=>{const c=t.replace(/^\.\//,""),n=e.replace(/^\.\//,"");if(n.startsWith(c))return t+n.slice(c.length);if(t.endsWith(e))return t;const l=P(t),u=P(e);let p=l.length-1,r=u.length-1;for(;p>=0&&r>=0&&l[p]===u[r];)p--,r--;let o=l.slice(0,p).join("/");const m=u.slice(r).join("/");return(!o.startsWith(".")||o==="")&&(o=`./${o}`),o+(m?`/${m}`:"")},"extendString");var Y=Object.defineProperty,Z=$((t,e)=>Y(t,"name",{value:e,configurable:!0}),"s");const ee=Z((...t)=>{if(t.length===0)return"";if(t.length===1)return S(t[0]);t=t.map(l=>w(l).split(F).join("/"));const[e,...c]=t;let n=e.split("/");for(const l of c){const u=l.split("/",n.length);let p=0;for(const r of u)if(r===n[p])p+=1;else{n=n.slice(0,p);break}n=n.slice(0,p)}return(n.length<=1&&n[0]===""?`/${n[0]}`:n.join("/")).split("/").join(F)},"lowestCommonAncestor");var te=Object.defineProperty,j=$((t,e)=>te(t,"name",{value:e,configurable:!0}),"u");const K=j((t,e)=>`${t}
|
|
2
|
+
//# sourceMappingURL=${O(e)}.map
|
|
3
|
+
`,"appendMapUrl"),I=j((t,e,c)=>JSON.stringify({file:O(c),mappings:t,names:[],sourceRoot:"",sources:[R(S(c),e)],version:3}),"generateDtsMap"),pe=j((t,e)=>{const c=U(e.options.include,e.options.exclude);let n=Object.create(null);const l=j((r,o)=>{n[r.replace(E,"")]={...o,ext:J(r)}},"addOutput");let u=[];e.tsconfig?.config.compilerOptions&&(u=Object.entries(e.tsconfig.config.compilerOptions.paths??{}).map(([r])=>r.endsWith("*")?new RegExp(`^${r.replace("*","(.*)")}$`):new RegExp(`^${r}$`)));async function p(r,o){if(!(o.endsWith(".ts")||o.endsWith(".cts")||o.endsWith(".mts")||o.endsWith(".tsx")||o.endsWith(".ctsx")||o.endsWith(".mtsx"))||!c(o))return;let m;try{m=(await X(o,r)).program}catch(i){e.logger.debug({message:i.message,prefix:"packem:isolated-declarations"})}if(m){const i=m.body.filter(s=>(s.type==="ImportDeclaration"||s.type==="ExportAllDeclaration"||s.type==="ExportNamedDeclaration")&&s.source);for await(const s of i){if(O(s.source.value).includes("."))continue;const a=await this.resolve(s.source.value,o);if(!(!a||a.external)&&(a.id.endsWith(".ts")||a.id.endsWith(".cts")||a.id.endsWith(".mts")||a.id.endsWith(".tsx")||a.id.endsWith(".ctsx")||a.id.endsWith(".mtsx"))){const f=a.id.replace(`${t}/`,"");let h=s.source.value;u.some(W=>W.test(s.source.value))&&!s.source.value.startsWith(".")&&(h=`./${s.source.value}`),r=r.replaceAll(`from "${s.source.value}"`,`from "${V(h,f)}"`)}}}const{errors:y,map:d,sourceText:b}=await e.options.isolatedDeclarationTransformer(o,r,e.options.sourcemap,e.tsconfig?.config?.compilerOptions);if(y.length>0){if(e.options.rollup.isolatedDeclarations.ignoreErrors){this.warn(y[0]);return}return this.error(y[0])}if(l(o,{map:d,source:b}),!m)return;const x=m.body.filter(i=>!("source"in i)||!i.source?!1:"importKind"in i&&i.importKind==="type"||"exportKind"in i&&i.exportKind==="type"?!0:i.type==="ImportDeclaration"?i.specifiers&&i.specifiers.every(s=>s.type==="ImportSpecifier"&&s.importKind==="type"):i.type==="ExportNamedDeclaration"&&i.specifiers&&i.specifiers.every(s=>s.exportKind==="type"));for await(const i of x){if(!i.source)continue;const s=await this.resolve(i.source.value,o);if(!s)return;const a=s.id;if(c(a)&&!n[a.replace(E,"")])try{const f=await _(a);await p.call(this,f,a)}catch{}}}return $(p,"v"),j(p,"transform"),{buildStart(){n=Object.create(null)},name:"packem:isolated-declarations",async renderStart(r,{input:o}){const m=ee(...Array.isArray(o)?o:Object.values(o));e.logger.debug({message:`Input base:${m}`,prefix:"packem:isolated-declarations"}),typeof r.entryFileNames=="function"&&(r.entryFileNames=r.entryFileNames({name:r.name}));const y=r.entryFileNames.replace(/\.(.)?[jt]sx?$/,(d,b)=>`.d.${b||""}ts`);for await(let[d,{ext:b,map:x,source:i}]of Object.entries(n)){let s;if(L(d)){if(!d.startsWith(t)){e.logger.debug({message:`Skipping file outside sourceDirectory: ${d}`,prefix:"packem:isolated-declarations"});continue}s=R(t,d)}else s=d.replace(`${t}/`,"");if(s.startsWith("/")&&(s=s.slice(1)),e.options.rollup.cjsInterop&&r.format==="cjs"){const g=q(i,{fileName:s,imports:[]},{warn:this.warn});g&&(i=g.code)}const a=i.includes("from '")?"'":'"',f=s+b;if((e.options.declaration===!0||e.options.declaration==="compatible")&&r.format==="cjs"){e.logger.debug({message:`Emit compatible dts file: ${s}`,prefix:"packem:isolated-declarations"});const g=y.replace("[name]",w(s)).replace(".cts",".ts");let v=i;e.options.sourcemap&&x&&(v=K(v.trim(),g),this.emitFile({fileName:`${g}.map`,originalFileName:f,source:I(x,f,k(r.dir,g)),type:"asset"})),this.emitFile({fileName:g,originalFileName:f,source:v.replaceAll(/(from\s)['|"]((.*)\..+|['|"].*)['|"];?/g,(D,N,M,T)=>`${N+a+(T||M)}.d.ts${a};`),type:"asset"})}e.logger.debug({message:`Emit dts file: ${s}`,prefix:"packem:isolated-declarations"});const h=y.replace("[name]",w(s));e.options.sourcemap&&x&&(i=K(i.trim(),h),this.emitFile({fileName:`${h}.map`,originalFileName:f,source:I(x,f,k(r.dir,h)),type:"asset"}));const W=C(e,r.format==="cjs"?"cjs":"esm");this.emitFile({fileName:h,originalFileName:f,source:i.replaceAll(/(from\s)['|"]((.*)\..+|['|"].*)['|"];?/g,(g,v,D,N)=>`${v+a+(N||D)}.${W}${a};`),type:"asset"})}},transform:p}},"isolatedDeclarationsPlugin");export{pe as isolatedDeclarationsPlugin};
|
|
@@ -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};
|