@visulima/packem-rollup 1.0.0-alpha.3 → 1.0.0-alpha.30
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 +267 -0
- package/LICENSE.md +199 -590
- package/README.md +89 -2
- package/dist/index.d.ts +24 -56
- package/dist/index.js +1 -0
- package/dist/packem_shared/cachingPlugin-CLawAGhx.js +1 -0
- package/dist/packem_shared/createSplitChunks-Ceq_Ca5Y.js +1 -0
- package/dist/packem_shared/esbuildPlugin-DpLtQGuZ.js +1 -0
- package/dist/packem_shared/index-QEzU3Fey.js +1 -0
- package/dist/packem_shared/{metafilePlugin-ObS4J7mO.mjs → metafilePlugin-CVcqFpPJ.js} +1 -1
- package/dist/packem_shared/oxcResolvePlugin-Ccef6pyL.js +1 -0
- package/dist/packem_shared/{patchTypescriptTypes-BEdkvKxL.mjs → patchTypescriptTypes-BX_sJsvd.js} +2 -2
- package/dist/packem_shared/resolveTsconfigPathsPlugin-CEasmDpi.js +1 -0
- package/dist/packem_shared/{resolveTsconfigRootDirectoriesPlugin-_93afm2q.mjs → resolveTsconfigRootDirectoriesPlugin-Cwj3tqCJ.js} +1 -1
- package/dist/plugins/cache-plugin.d.ts +11 -0
- package/dist/plugins/chunk-splitter/gather.d.ts +8 -0
- package/dist/plugins/chunk-splitter/index.d.ts +6 -0
- package/dist/plugins/chunk-splitter/parse/index.d.ts +4 -0
- package/dist/plugins/chunk-splitter/parse/types.d.ts +24 -0
- package/dist/plugins/cjs-interop.d.ts +7 -0
- package/dist/{packem_shared/cjsInteropPlugin-D5wyoQ_B.mjs → plugins/cjs-interop.js} +1 -1
- package/dist/plugins/copy.d.ts +23 -0
- package/dist/plugins/copy.js +1 -0
- package/dist/plugins/data-uri.d.ts +25 -0
- package/dist/plugins/data-uri.js +1 -0
- package/dist/plugins/debarrel.d.ts +7 -0
- package/dist/plugins/debarrel.js +2 -0
- package/dist/{packem_shared/browserslist-to-esbuild-DY9HwYtp.d.mts → plugins/esbuild/browserslist-to-esbuild.d.ts} +1 -2
- package/dist/plugins/esbuild/esbuild-plugin.d.ts +3 -0
- package/dist/plugins/esbuild/index.d.ts +3 -25
- package/dist/plugins/esbuild/index.js +1 -0
- package/dist/plugins/esbuild/types.d.ts +39 -0
- package/dist/plugins/esbuild/utils/get-render-chunk.d.ts +14 -0
- package/dist/plugins/esbuild/utils/optimize-deps.d.ts +3 -0
- package/dist/plugins/esbuild/utils/warn.d.ts +4 -0
- package/dist/plugins/esm-shim-cjs-syntax.d.ts +9 -0
- package/dist/plugins/fix-dts-default-cjs-exports.d.ts +26 -0
- package/dist/plugins/fix-dts-default-cjs-exports.js +1 -0
- package/dist/plugins/fix-dynamic-import-extension.d.ts +3 -0
- package/dist/plugins/isolated-declarations/index.d.ts +8 -0
- package/dist/plugins/isolated-declarations/index.js +3 -0
- package/dist/plugins/isolated-declarations/utils/extend-string.d.ts +2 -0
- package/dist/plugins/isolated-declarations/utils/fix-dts-default-cjs-exports.d.ts +35 -0
- package/dist/plugins/isolated-declarations/utils/lowest-common-ancestor.d.ts +2 -0
- package/dist/plugins/isolated-declarations/utils/split-tsconfig-path-key.d.ts +2 -0
- package/dist/plugins/json.d.ts +4 -0
- package/dist/plugins/json.js +1 -0
- package/dist/plugins/jsx-remove-attributes.d.ts +7 -0
- package/dist/plugins/jsx-remove-attributes.js +1 -0
- package/dist/plugins/license.d.ts +17 -0
- package/dist/plugins/license.js +13 -0
- package/dist/plugins/metafile.d.ts +3 -0
- package/dist/plugins/minify-html-literals/index.d.ts +41 -0
- package/dist/plugins/minify-html-literals/index.js +3 -0
- package/dist/plugins/minify-html-literals/lib/minify-html-literals.d.ts +200 -0
- package/dist/plugins/minify-html-literals/lib/models.d.ts +25 -0
- package/dist/plugins/minify-html-literals/lib/parse-literals.d.ts +13 -0
- package/dist/plugins/minify-html-literals/lib/strategy.d.ts +69 -0
- package/dist/plugins/minify-html-literals/lib/typescript.d.ts +23 -0
- package/dist/plugins/native-modules-plugin.d.ts +14 -0
- package/dist/plugins/native-modules-plugin.js +1 -0
- package/dist/plugins/oxc/index.d.ts +4 -28
- package/dist/plugins/oxc/index.js +1 -0
- package/dist/plugins/oxc/isolated-declarations-oxc-transformer.d.ts +4 -0
- package/dist/plugins/oxc/oxc-resolve-plugin.d.ts +4 -0
- package/dist/plugins/oxc/oxc-transformer-plugin.d.ts +3 -0
- package/dist/plugins/oxc/types.d.ts +16 -0
- package/dist/plugins/preserve-directives.d.ts +16 -0
- package/dist/{packem_shared/preserveDirectivesPlugin-B49Cbykd.mjs → plugins/preserve-directives.js} +3 -3
- package/dist/plugins/raw.d.ts +7 -0
- package/dist/plugins/raw.js +6 -0
- package/dist/plugins/require-cjs-transformer.d.ts +43 -0
- package/dist/plugins/require-cjs-transformer.js +21 -0
- package/dist/plugins/resolve-file-url.d.ts +3 -0
- package/dist/plugins/shebang.d.ts +9 -0
- package/dist/plugins/source-maps.d.ts +7 -0
- package/dist/plugins/sucrase/index.d.ts +8 -19
- package/dist/plugins/swc/index.d.ts +3 -26
- package/dist/plugins/swc/index.js +1 -0
- package/dist/plugins/swc/isolated-declarations-swc-transformer.d.ts +3 -0
- package/dist/plugins/swc/swc-plugin.d.ts +3 -0
- package/dist/plugins/swc/types.d.ts +6 -0
- package/dist/plugins/typescript/index.d.ts +8 -29
- package/dist/plugins/typescript/index.js +1 -0
- package/dist/plugins/typescript/isolated-declarations-typescript-transformer.d.ts +4 -0
- package/dist/plugins/typescript/patch-typescript-types.d.ts +13 -0
- package/dist/plugins/typescript/resolve-tsconfig-paths-plugin.d.ts +11 -0
- package/dist/plugins/typescript/resolve-tsconfig-root-dirs.d.ts +24 -0
- package/dist/plugins/typescript/resolve-typescript-mjs-cjs.d.ts +10 -0
- package/dist/plugins/url.d.ts +72 -0
- package/dist/plugins/url.js +1 -0
- package/dist/types.d.ts +133 -0
- package/dist/utils/chunks/create-split-chunks.d.ts +11 -0
- package/dist/utils/chunks/get-custom-module-layer.d.ts +2 -0
- package/dist/utils/chunks/get-module-layer.d.ts +10 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/is-pure-cjs.d.ts +9 -0
- package/package.json +104 -29
- package/dist/index.d.mts +0 -56
- package/dist/index.mjs +0 -1
- package/dist/packem_shared/browserslist-to-esbuild-DY9HwYtp.d.ts +0 -3
- package/dist/packem_shared/cachingPlugin-D0BBFJPD.mjs +0 -1
- package/dist/packem_shared/copyPlugin--6RITp1-.mjs +0 -1
- package/dist/packem_shared/createSplitChunks-CGDk55G3.mjs +0 -1
- package/dist/packem_shared/esbuildPlugin-BAwyhG6L.mjs +0 -1
- package/dist/packem_shared/fixDtsDefaultCjsExportsPlugin-Dp1UcHVR.mjs +0 -1
- package/dist/packem_shared/isolatedDeclarationsPlugin-A0wmmw3Y.mjs +0 -3
- package/dist/packem_shared/jsonPlugin-BAi3Da-h.mjs +0 -1
- package/dist/packem_shared/jsxRemoveAttributes-B1PLPffj.mjs +0 -1
- package/dist/packem_shared/licensePlugin-C5yzUqe-.mjs +0 -13
- package/dist/packem_shared/oxcResolvePlugin-BJpi-eSG.mjs +0 -1
- package/dist/packem_shared/rawPlugin-BqlR6ZOI.mjs +0 -1
- package/dist/packem_shared/resolveTsconfigPathsPlugin-Crf4lzxq.mjs +0 -1
- package/dist/packem_shared/types-C_grznAP.d.mts +0 -4539
- package/dist/packem_shared/types-C_grznAP.d.ts +0 -4539
- package/dist/packem_shared/urlPlugin-DBgFIkTc.mjs +0 -1
- package/dist/plugins/esbuild/index.d.mts +0 -25
- package/dist/plugins/esbuild/index.mjs +0 -1
- package/dist/plugins/oxc/index.d.mts +0 -28
- package/dist/plugins/oxc/index.mjs +0 -1
- package/dist/plugins/sucrase/index.d.mts +0 -19
- package/dist/plugins/swc/index.d.mts +0 -26
- package/dist/plugins/swc/index.mjs +0 -1
- package/dist/plugins/typescript/index.d.mts +0 -29
- package/dist/plugins/typescript/index.mjs +0 -1
- /package/dist/packem_shared/{browserslistToEsbuild-C0IWmbNe.mjs → browserslistToEsbuild-C0IWmbNe.js} +0 -0
- /package/dist/packem_shared/{chunkSplitter-DWAy1JkE.mjs → chunkSplitter-DWAy1JkE.js} +0 -0
- /package/dist/packem_shared/{fix-dts-default-cjs-exports-BQc0nwIG.mjs → fix-dts-default-cjs-exports-BQc0nwIG.js} +0 -0
- /package/dist/packem_shared/{fixDynamicImportExtension-BBGNRniz.mjs → fixDynamicImportExtension-BBGNRniz.js} +0 -0
- /package/dist/packem_shared/{getCustomModuleLayer-d8i66lfh.mjs → getCustomModuleLayer-d8i66lfh.js} +0 -0
- /package/dist/packem_shared/{getModuleLayer-rF9RxnJ5.mjs → getModuleLayer-rF9RxnJ5.js} +0 -0
- /package/dist/packem_shared/{index-Dq8IUFTs.mjs → index-Dq8IUFTs.js} +0 -0
- /package/dist/packem_shared/{isolatedDeclarationsOxcTransformer-WbfE6cGu.mjs → isolatedDeclarationsOxcTransformer-WbfE6cGu.js} +0 -0
- /package/dist/packem_shared/{isolatedDeclarationsSwcTransformer-Ch2AgtWC.mjs → isolatedDeclarationsSwcTransformer-Ch2AgtWC.js} +0 -0
- /package/dist/packem_shared/{isolatedDeclarationsTypescriptTransformer-DkuEkofo.mjs → isolatedDeclarationsTypescriptTransformer-DkuEkofo.js} +0 -0
- /package/dist/packem_shared/{oxcTransformPlugin-DfVQouIB.mjs → oxcTransformPlugin-DfVQouIB.js} +0 -0
- /package/dist/packem_shared/{resolveFileUrl-BkpjVHeK.mjs → resolveFileUrlPlugin-BkpjVHeK.js} +0 -0
- /package/dist/packem_shared/{resolveTypescriptMjsCtsPlugin-DcZrZTmM.mjs → resolveTypescriptMjsCtsPlugin-DcZrZTmM.js} +0 -0
- /package/dist/packem_shared/{swcPlugin-Boip4lWG.mjs → swcPlugin-Boip4lWG.js} +0 -0
- /package/dist/{packem_shared/esmShimCjsSyntaxPlugin-DjKqX4DE.mjs → plugins/esm-shim-cjs-syntax.js} +0 -0
- /package/dist/{packem_shared/makeExecutable-6aOVHoJR.mjs → plugins/shebang.js} +0 -0
- /package/dist/{packem_shared/sourcemapsPlugin-B4W3J79w.mjs → plugins/source-maps.js} +0 -0
- /package/dist/plugins/sucrase/{index.mjs → index.js} +0 -0
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
import '@rollup/plugin-alias';
|
|
5
|
-
import '@rollup/plugin-commonjs';
|
|
6
|
-
import '@rollup/plugin-json';
|
|
7
|
-
import '@rollup/plugin-node-resolve';
|
|
8
|
-
import '@rollup/plugin-replace';
|
|
9
|
-
import '@rollup/plugin-wasm';
|
|
10
|
-
import '@rollup/pluginutils';
|
|
11
|
-
import 'rollup';
|
|
12
|
-
import 'rollup-plugin-dts';
|
|
13
|
-
import 'rollup-plugin-polyfill-node';
|
|
14
|
-
import 'rollup-plugin-pure';
|
|
15
|
-
import 'rollup-plugin-visualizer';
|
|
16
|
-
import 'esbuild';
|
|
17
|
-
import '@visulima/package';
|
|
18
|
-
import '@visulima/packem-share/types';
|
|
19
|
-
import 'oxc-resolver';
|
|
20
|
-
import 'oxc-transform';
|
|
21
|
-
import 'sucrase';
|
|
22
|
-
|
|
23
|
-
declare const _default: TransformerFn;
|
|
24
|
-
|
|
25
|
-
export { _default as esbuildPlugin };
|
|
1
|
+
export { default as browserslistToEsbuild } from "./browserslist-to-esbuild.d.ts";
|
|
2
|
+
export { default as esbuildPlugin } from "./esbuild-plugin.d.ts";
|
|
3
|
+
export type * from "./types.d.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{default as l}from"../../packem_shared/browserslistToEsbuild-C0IWmbNe.js";import{default as r}from"../../packem_shared/esbuildPlugin-DpLtQGuZ.js";export{l as browserslistToEsbuild,r as esbuildPlugin};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modified copy of https://github.com/egoist/rollup-plugin-esbuild/blob/dev/src/index.ts
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2020 EGOIST
|
|
7
|
+
*/
|
|
8
|
+
import type { FilterPattern } from "@rollup/pluginutils";
|
|
9
|
+
import type { BuildOptions as EsbuildOptions, Loader, TransformOptions } from "esbuild";
|
|
10
|
+
type MarkOptional<Type, Keys extends keyof Type> = Type extends Type ? Omit<Type, Keys> & Partial<Pick<Type, Keys>> : never;
|
|
11
|
+
export type EsbuildPluginConfig = Options & {
|
|
12
|
+
logger: Console;
|
|
13
|
+
};
|
|
14
|
+
export type Optimized = Map<string, {
|
|
15
|
+
file: string;
|
|
16
|
+
}>;
|
|
17
|
+
export type OptimizeDepsOptions = {
|
|
18
|
+
cwd: string;
|
|
19
|
+
esbuildOptions?: EsbuildOptions;
|
|
20
|
+
exclude?: string[];
|
|
21
|
+
include: string[];
|
|
22
|
+
sourceMap: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type OptimizeDepsResult = {
|
|
25
|
+
cacheDir: string;
|
|
26
|
+
optimized: Optimized;
|
|
27
|
+
};
|
|
28
|
+
export type Options = Omit<TransformOptions, "loader" | "sourcemap"> & {
|
|
29
|
+
exclude?: FilterPattern;
|
|
30
|
+
include?: FilterPattern;
|
|
31
|
+
/**
|
|
32
|
+
* Map extension to esbuild loader
|
|
33
|
+
* Note that each entry (the extension) needs to start with a dot
|
|
34
|
+
*/
|
|
35
|
+
loaders?: Record<string, Loader | false>;
|
|
36
|
+
optimizeDeps?: MarkOptional<OptimizeDepsOptions, "cwd" | "sourceMap">;
|
|
37
|
+
sourceMap?: boolean;
|
|
38
|
+
};
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modified copy of https://github.com/egoist/rollup-plugin-esbuild/blob/dev/src/minify.ts
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2020 EGOIST
|
|
7
|
+
*/
|
|
8
|
+
import type { TransformOptions } from "esbuild";
|
|
9
|
+
import type { Plugin } from "rollup";
|
|
10
|
+
type Options = Omit<TransformOptions, "sourcemap"> & {
|
|
11
|
+
sourceMap?: boolean;
|
|
12
|
+
};
|
|
13
|
+
declare const getRenderChunk: ({ sourceMap, ...options }: Options) => Plugin["renderChunk"];
|
|
14
|
+
export default getRenderChunk;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FilterPattern } from "@rollup/pluginutils";
|
|
2
|
+
import type { PackageJson } from "@visulima/package";
|
|
3
|
+
import type { Plugin } from "rollup";
|
|
4
|
+
export declare const GLOBAL_REQUIRE_REGEX: RegExp;
|
|
5
|
+
export interface EsmShimCjsSyntaxOptions {
|
|
6
|
+
exclude?: FilterPattern;
|
|
7
|
+
include?: FilterPattern;
|
|
8
|
+
}
|
|
9
|
+
export declare const esmShimCjsSyntaxPlugin: (packageJson: PackageJson, options: EsmShimCjsSyntaxOptions) => Plugin;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Plugin, RenderedChunk } from "rollup";
|
|
2
|
+
export type FixDtsDefaultCjsExportsPluginOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* A function to determine if a chunk should be processed by this plugin.
|
|
5
|
+
* Defaults to processing .d.ts, .d.cts, or .d.mts files that are entry chunks and have exports.
|
|
6
|
+
* @param info The Rollup RenderedChunk object.
|
|
7
|
+
* @returns True if the chunk should be processed, false otherwise.
|
|
8
|
+
*/
|
|
9
|
+
matcher?: (info: RenderedChunk) => boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A Rollup plugin to fix default exports in TypeScript declaration files (.d.ts)
|
|
13
|
+
* to ensure they are CJS compatible (using `export = ...` and namespaces).
|
|
14
|
+
* This is particularly useful for libraries that want to support both ESM and CJS consumers correctly.
|
|
15
|
+
*
|
|
16
|
+
* The plugin handles various scenarios:
|
|
17
|
+
* - `export { MyClass as default };`
|
|
18
|
+
* - `export { default } from 'some-module';`
|
|
19
|
+
* - `export { name as default } from 'some-module';`
|
|
20
|
+
* - `export default from 'some-module';` (an mlly quirk)
|
|
21
|
+
* - Combinations with named exports (value and type exports), creating namespaces where appropriate.
|
|
22
|
+
* - Pure type-only exports like `export { type Foo, type Bar };`
|
|
23
|
+
* @param options Optional configuration for the plugin.
|
|
24
|
+
* @returns The Rollup plugin object.
|
|
25
|
+
*/
|
|
26
|
+
export declare const fixDtsDefaultCjsExportsPlugin: (options?: FixDtsDefaultCjsExportsPluginOptions) => Plugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var i=Object.defineProperty;var n=(e,r)=>i(e,"name",{value:r,configurable:!0});import{_ as o}from"../packem_shared/fix-dts-default-cjs-exports-BQc0nwIG.js";var p=Object.defineProperty,a=n((e,r)=>p(e,"name",{value:r,configurable:!0}),"n");const l=a((e={})=>{const{matcher:r=a(t=>(t.type==="chunk"||t.type==="asset")&&t.exports?.length>0&&/\.d\.c?ts$/.test(t.fileName)&&t.isEntry,"matcher")}=e;return{name:"packem:fix-dts-default-cjs-exports-plugin",renderChunk(t,s){return r(s)?o(t,{fileName:s.fileName,imports:s.imports},{warn:this.warn}):void 0}}},"fixDtsDefaultCjsExportsPlugin");export{l as fixDtsDefaultCjsExportsPlugin};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FilterPattern } from "@rollup/pluginutils";
|
|
2
|
+
import type { BuildContext } from "@visulima/packem-share/types";
|
|
3
|
+
import type { Plugin } from "rollup";
|
|
4
|
+
export type IsolatedDeclarationsOptions = {
|
|
5
|
+
exclude?: FilterPattern;
|
|
6
|
+
ignoreErrors?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const isolatedDeclarationsPlugin: <T extends Record<string, any>>(sourceDirectory: string, context: BuildContext<T>) => Plugin;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var U=Object.defineProperty;var x=(t,e)=>U(t,"name",{value:e,configurable:!0});import{createFilter as X}from"@rollup/pluginutils";import{readFile as W}from"@visulima/fs";import{EXCLUDE_REGEXP as _,ENDING_REGEX as E}from"@visulima/packem-share/constants";import{getDtsExtension as L}from"@visulima/packem-share/utils";import{dirname as R,toNamespacedPath as D,sep as k,extname as J,isAbsolute as q,relative as C,join as A,basename as O}from"@visulima/path";import{parseSync as z}from"oxc-parser";import{_ as B}from"../../packem_shared/fix-dts-default-cjs-exports-BQc0nwIG.js";var H=Object.defineProperty,Q=x((t,e)=>H(t,"name",{value:e,configurable:!0}),"e");const P=/^([\w-]+):/,K=Q(t=>{if(!t||typeof t!="string")throw new Error("Invalid key: Key must be a non-empty string.");const e=[],c=P.exec(t);c&&(e.push(c[1]),t=t.replace(P,""));const n=t.split("/");for(const p of n)(p.includes("*")||p)&&e.push(p);return e},"splitTsconfigPathKey");var V=Object.defineProperty,Y=x((t,e)=>V(t,"name",{value:e,configurable:!0}),"h");const Z=Y((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 p=K(t),d=K(e);let l=p.length-1,r=d.length-1;for(;l>=0&&r>=0&&p[l]===d[r];)l--,r--;let a=p.slice(0,l).join("/");const f=d.slice(r).join("/");return(!a.startsWith(".")||a==="")&&(a=`./${a}`),a+(f?`/${f}`:"")},"extendString");var ee=Object.defineProperty,te=x((t,e)=>ee(t,"name",{value:e,configurable:!0}),"s");const re=te((...t)=>{if(t.length===0)return"";if(t.length===1)return R(t[0]);t=t.map(p=>D(p).split(k).join("/"));const[e,...c]=t;let n=e.split("/");for(const p of c){const d=p.split("/",n.length);let l=0;for(const r of d)if(r===n[l])l+=1;else{n=n.slice(0,l);break}n=n.slice(0,l)}return(n.length<=1&&n[0]===""?`/${n[0]}`:n.join("/")).split("/").join(k)},"lowestCommonAncestor");var ie=Object.defineProperty,j=x((t,e)=>ie(t,"name",{value:e,configurable:!0}),"g");const S=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:[C(R(c),e)],version:3}),"generateDtsMap"),fe=j((t,e)=>{const c=X(/\.(?:[mc]?ts|[jt]sx?)$/,e.options.rollup.isolatedDeclarations?.exclude||_);let n=Object.create(null);const p=j((r,a)=>{n[r.replace(E,"")]={...a,ext:J(r)}},"addOutput");let d=[];e.tsconfig?.config.compilerOptions&&(d=Object.entries(e.tsconfig.config.compilerOptions.paths??{}).map(([r])=>r.endsWith("*")?new RegExp(`^${r.replace("*","(.*)")}$`):new RegExp(`^${r}$`)));async function l(r,a){if(!c(a))return;e.logger.debug({message:`Processing file: ${a}`,prefix:"packem:isolated-declarations"});let f;try{f=z(a,r).program}catch(s){e.logger.debug({message:s.message,prefix:"packem:isolated-declarations"})}if(f){const s=f.body.filter(i=>(i.type==="ImportDeclaration"||i.type==="ExportAllDeclaration"||i.type==="ExportNamedDeclaration")&&i.source);for await(const i of s){if(O(i.source.value).includes("."))continue;const o=await this.resolve(i.source.value,a);if(!(!o||o.external)&&(o.id.endsWith(".ts")||o.id.endsWith(".cts")||o.id.endsWith(".mts")||o.id.endsWith(".tsx")||o.id.endsWith(".ctsx")||o.id.endsWith(".mtsx"))){const g=o.id.replace(`${t}/`,"");let u=i.source.value;d.some($=>$.test(i.source.value))&&!i.source.value.startsWith(".")&&(u=`./${i.source.value}`),r=r.replaceAll(`from "${i.source.value}"`,`from "${Z(u,g)}"`)}}}const{errors:b,map:w,sourceText:m}=await e.options.isolatedDeclarationTransformer(a,r,e.options.sourcemap,e.tsconfig?.config?.compilerOptions);if(b.length>0){if(e.options.rollup.isolatedDeclarations.ignoreErrors){this.warn(b[0]);return}return this.error(b[0])}if(p(a,{map:w,source:m}),!f)return;const h=f.body.filter(s=>!("source"in s)||!s.source?!1:"importKind"in s&&s.importKind==="type"||"exportKind"in s&&s.exportKind==="type"?!0:s.type==="ImportDeclaration"?s.specifiers&&s.specifiers.every(i=>i.type==="ImportSpecifier"&&i.importKind==="type"):s.type==="ExportNamedDeclaration"&&s.specifiers&&s.specifiers.every(i=>i.exportKind==="type"));for await(const s of h){if(!s.source)continue;const i=await this.resolve(s.source.value,a);if(!i)return;const o=i.id;if(c(o)&&!n[o.replace(E,"")])try{const g=await W(o);await l.call(this,g,o)}catch{}}}return x(l,"N"),j(l,"transform"),{buildStart(){n=Object.create(null)},name:"packem:isolated-declarations",async renderStart(r,{input:a}){const f=re(...Array.isArray(a)?a:Object.values(a));e.logger.debug({message:`Input base:${f}`,prefix:"packem:isolated-declarations"});const b=Array.isArray(a)?a:Object.values(a);for await(const m of b)if(c(m)&&!n[m.replace(E,"")])try{const h=await W(m);await l.call(this,h,m)}catch{}typeof r.entryFileNames=="function"&&(r.entryFileNames=r.entryFileNames({name:r.name}));const w=r.entryFileNames.replace(/\.(.)?[jt]sx?$/,(m,h)=>`.d.${h||""}ts`);for await(let[m,{ext:h,map:s,source:i}]of Object.entries(n)){let o;if(q(m)){if(!m.startsWith(t)){e.logger.debug({message:`Skipping file outside sourceDirectory: ${m}`,prefix:"packem:isolated-declarations"});continue}o=C(t,m)}else o=m.replace(`${t}/`,"");if(o.startsWith("/")&&(o=o.slice(1)),e.options.rollup.cjsInterop&&r.format==="cjs"){const y=B(i,{fileName:o,imports:[]},{warn:this.warn});y&&(i=y.code)}const g=i.includes("from '")?"'":'"',u=o+h;if((e.options.declaration===!0||e.options.declaration==="compatible")&&r.format==="cjs"){e.logger.debug({message:`Emit compatible dts file: ${o}`,prefix:"packem:isolated-declarations"});const y=w.replace("[name]",D(o)).replace(".cts",".ts");let v=i;e.options.sourcemap&&s&&(v=S(v.trim(),y),this.emitFile({fileName:`${y}.map`,originalFileName:u,source:I(s,u,A(r.dir,y)),type:"asset"})),this.emitFile({fileName:y,originalFileName:u,source:v.replaceAll(/(from\s)['|"]((.*)\..+|['|"].*)['|"];?/g,(F,N,M,T)=>`${N+g+(T||M)}.d.ts${g};`),type:"asset"})}e.logger.debug({message:`Emit dts file: ${o}`,prefix:"packem:isolated-declarations"});const $=w.replace("[name]",D(o));e.options.sourcemap&&s&&(i=S(i.trim(),$),this.emitFile({fileName:`${$}.map`,originalFileName:u,source:I(s,u,A(r.dir,$)),type:"asset"}));const G=L(e,r.format==="cjs"?"cjs":"esm");this.emitFile({fileName:$,originalFileName:u,source:i.replaceAll(/(from\s)['|"]((.*)\..+|['|"].*)['|"];?/g,(y,v,F,N)=>`${v+g+(N||F)}.${G}${g};`),type:"asset"})}},transform:l}},"isolatedDeclarationsPlugin");export{fe as isolatedDeclarationsPlugin};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { LoggingFunction, SourceMapInput } from "rollup";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the plugin.
|
|
4
|
+
*/
|
|
5
|
+
type Options = {
|
|
6
|
+
/**
|
|
7
|
+
* Rollup's warning function.
|
|
8
|
+
*/
|
|
9
|
+
warn?: LoggingFunction;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Information about the code being processed.
|
|
13
|
+
*/
|
|
14
|
+
interface CodeInfo {
|
|
15
|
+
/**
|
|
16
|
+
* The name of the file.
|
|
17
|
+
*/
|
|
18
|
+
fileName: string;
|
|
19
|
+
/**
|
|
20
|
+
* A list of import specifiers in the file.
|
|
21
|
+
*/
|
|
22
|
+
imports: string[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Main internal function to transform ES module default exports in .d.ts files to be CJS compatible.
|
|
26
|
+
* @param code The code of the chunk.
|
|
27
|
+
* @param info Information about the file (name, imports).
|
|
28
|
+
* @param options Plugin options, including the warning function.
|
|
29
|
+
* @returns An object with the transformed code and a null map, or undefined if no transformation occurs or an error happens.
|
|
30
|
+
*/
|
|
31
|
+
declare const fixDtsDefaultCJSExports: (code: string, info: CodeInfo, options: Options) => {
|
|
32
|
+
code: string;
|
|
33
|
+
map: SourceMapInput | undefined;
|
|
34
|
+
} | undefined;
|
|
35
|
+
export default fixDtsDefaultCJSExports;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var c=Object.defineProperty;var t=(o,r)=>c(o,"name",{value:r,configurable:!0});import i from"@rollup/plugin-json";var l=Object.defineProperty,d=t((o,r)=>l(o,"name",{value:r,configurable:!0}),"t");const n="export default ",m=d(o=>{const r=i(o);return{...r,name:"packem:json",transform:{filter:{id:/\.json$/},handler(s,a){const e=r.transform?.call(this,s,a);return e&&typeof e!="string"&&"code"in e&&e.code?.startsWith(n)&&(e.code=e.code.replace(n,"module.exports = ")),e}}}},"JsonPlugin");export{m as JsonPlugin};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var c=Object.defineProperty;var p=(e,a)=>c(e,"name",{value:a,configurable:!0});import{w as y}from"../packem_shared/index-Dq8IUFTs.js";import f from"magic-string";var b=Object.defineProperty,v=p((e,a)=>b(e,"name",{value:a,configurable:!0}),"l");const g=v(({attributes:e,logger:a})=>{if(!Array.isArray(e)||e.length===0)throw new Error("[packem:jsx-remove-attributes]: attributes must be a non-empty array of strings.");return{name:"packem:jsx-remove-attributes",transform:{filter:{id:/\.[tj]sx$/},async handler(i,u){let n;try{n=this.parse(i,{allowReturnOutsideFunction:!0})}catch(r){this.warn({code:"PARSE_ERROR",message:`[packem:jsx-remove-attributes]: failed to parse "${u}" and remove the jsx attribute.`}),a.warn(r);return}let l=!1;const o=new f(i);if(y(n,{enter(r){if(r.type==="CallExpression"&&r.callee.type==="Identifier"&&r.callee.name==="jsx"){const m=r.arguments.filter(s=>s.type==="ObjectExpression"&&Array.isArray(s.properties));for(const s of m)for(const t of s.properties)t.type==="Property"&&t.key.type==="Literal"&&t.value.type==="Literal"&&e.includes(t.key.value)&&(o.overwrite(t.start-2,t.end,""),l=!0)}}}),!!l)return{code:o.toString(),map:o.generateMap({hires:!0})}}}}},"jsxRemoveAttributes");export{g as jsxRemoveAttributes};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Plugin } from "rollup";
|
|
2
|
+
export interface LicenseOptions {
|
|
3
|
+
dependenciesMarker?: string;
|
|
4
|
+
dependenciesTemplate?: (licenses: string[], dependencyLicenseTexts: string, packageName: string | undefined) => string;
|
|
5
|
+
dtsMarker?: string;
|
|
6
|
+
dtsTemplate?: (licenses: string[], dependencyLicenseTexts: string, packageName: string | undefined) => string;
|
|
7
|
+
path?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const licensePlugin: ({ dtsMarker, licenseFilePath, licenseTemplate, logger, marker, mode, packageName, }: {
|
|
10
|
+
dtsMarker?: string;
|
|
11
|
+
licenseFilePath: string;
|
|
12
|
+
licenseTemplate: (licenses: string[], dependencyLicenseTexts: string, packageName: string | undefined) => string;
|
|
13
|
+
logger: Console;
|
|
14
|
+
marker: string;
|
|
15
|
+
mode: "dependencies" | "types";
|
|
16
|
+
packageName: string | undefined;
|
|
17
|
+
}) => Plugin;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var P=Object.defineProperty;var h=(r,e)=>P(r,"name",{value:e,configurable:!0});import{readFileSync as b,writeFileSync as v}from"@visulima/fs";import{replaceContentWithinMarker as w}from"@visulima/packem-share/utils";import F from"rollup-plugin-license";var N=Object.defineProperty,y=h((r,e)=>N(r,"name",{value:e,configurable:!0}),"d");const C=y(r=>{const e=[],c=[];return r.forEach(t=>{t.startsWith("(")?e.push(t):c.push(t)}),[...c.toSorted(),...e.toSorted()]},"sortLicenses"),z=y(({dtsMarker:r,licenseFilePath:e,licenseTemplate:c,logger:t,marker:s,mode:m,packageName:S})=>F({thirdParty(x){const u=new Set,d=x.toSorted(({name:n},{name:i})=>(n||0)>(i||0)?1:(i||0)>(n||0)?-1:0).map(({author:n,contributors:i,license:a,licenseText:$,maintainers:j,name:k,repository:p})=>{let l=`## ${k}
|
|
2
|
+
`;a&&(l+=`License: ${a}
|
|
3
|
+
`);const f=new Set;for(const o of[n,...j,...i]){const g=typeof o=="string"?o:o?.name;g&&f.add(g)}return f.size>0&&(l+=`By: ${[...f].join(", ")}
|
|
4
|
+
`),p&&(l+=`Repository: ${typeof p=="string"?p:p.url}
|
|
5
|
+
`),$&&(l+=`
|
|
6
|
+
${$.trim().replaceAll(/\r\n|\r/g,`
|
|
7
|
+
`).replaceAll(`<!-- ${s} -->`,"").replaceAll(r?`<!-- ${r} -->`:"","").replaceAll(`<!-- /${s} -->`,"").replaceAll(r?`<!-- /${r} -->`:"","").trim().split(`
|
|
8
|
+
`).map(o=>o?`> ${o}`:">").join(`
|
|
9
|
+
`)}
|
|
10
|
+
`),a&&u.add(a),l}).join(`
|
|
11
|
+
---------------------------------------
|
|
12
|
+
|
|
13
|
+
`);if(d===""){t.info({message:"No dependencies license information found.",prefix:`plugin:license:${m}`});return}const A=c(C(u),d,S);try{const n=b(e),i=w(n,s,A);if(!i){t.error({message:`Could not find the license marker: <!-- ${s} --><!-- /${s} --> in ${e}`,prefix:`plugin:license:${m}`});return}n!==i&&(v(e,i),t.info({message:`${e} updated.`,prefix:`plugin:license:${m}`}))}catch(n){t.error(n)}}}),"licensePlugin");export{z as licensePlugin};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ported from https://github.com/lit/lit/tree/main/packages/labs/rollup-plugin-minify-html-literals
|
|
3
|
+
*
|
|
4
|
+
* BSD-3-Clause License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2024 Google LLC
|
|
7
|
+
*/
|
|
8
|
+
import type { FilterPattern } from "@rollup/pluginutils";
|
|
9
|
+
import type { Plugin } from "rollup";
|
|
10
|
+
import * as minify from "./lib/minify-html-literals.d.ts";
|
|
11
|
+
/**
|
|
12
|
+
* Plugin options.
|
|
13
|
+
*/
|
|
14
|
+
export interface MinifyHTMLLiteralsOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Pattern or array of patterns of files not to minify.
|
|
17
|
+
*/
|
|
18
|
+
exclude?: FilterPattern;
|
|
19
|
+
/**
|
|
20
|
+
* If true, any errors while parsing or minifying will abort the bundle
|
|
21
|
+
* process. Defaults to false, which will only show a warning.
|
|
22
|
+
*/
|
|
23
|
+
failOnError?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Pattern or array of patterns of files to minify.
|
|
26
|
+
*/
|
|
27
|
+
include?: FilterPattern;
|
|
28
|
+
/**
|
|
29
|
+
* Override minify-html-literals function.
|
|
30
|
+
*/
|
|
31
|
+
minifyHTMLLiterals?: typeof minify.minifyHTMLLiterals;
|
|
32
|
+
/**
|
|
33
|
+
* Minify options, see
|
|
34
|
+
* https://www.npmjs.com/package/minify-html-literals#options.
|
|
35
|
+
*/
|
|
36
|
+
options?: Partial<minify.Options>;
|
|
37
|
+
}
|
|
38
|
+
export declare const minifyHTMLLiteralsPlugin: ({ exclude, failOnError, include, logger, minifyHTMLLiterals, options, }: MinifyHTMLLiteralsOptions & {
|
|
39
|
+
logger: Console;
|
|
40
|
+
}) => Plugin;
|
|
41
|
+
export default minifyHTMLLiteralsPlugin;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var b=Object.defineProperty;var g=(t,e)=>b(t,"name",{value:e,configurable:!0});import{createFilter as E}from"@rollup/pluginutils";import H from"magic-string";import p from"typescript";import N from"clean-css";import{minify as j}from"html-minifier-next";let y;const A={getHeadTemplatePart(t){const e=t.getFullText(y),i=e.indexOf("`")+1,r=p.isTemplateHead(t)?-2:-1;return{end:t.end+r,start:t.pos+i,text:e.slice(i,e.length+r)}},getMiddleTailTemplatePart(t){const e=t.getText(y),i=p.isTemplateMiddle(t)?2:1;return{end:t.end-i,start:t.getStart(y)+1,text:e.slice(1,e.length-i)}},getRootNode(t,e=""){return p.createSourceFile(e,t,p.ScriptTarget.ESNext)},getTaggedTemplateTemplate(t){return t.template},getTagText(t){return t.tag.getText(y)},getTemplateParts(t){return p.isNoSubstitutionTemplateLiteral(t)?[this.getHeadTemplatePart(t)]:[this.getHeadTemplatePart(t.head),...t.templateSpans.map(e=>this.getMiddleTailTemplatePart(e.literal))]},isTaggedTemplate:p.isTaggedTemplateExpression,isTemplate:p.isTemplateLiteral,walkChildNodes(t,e){e(t),p.forEachChild(t,i=>{this.walkChildNodes(i,e)})},walkNodes(t,e){y=t,this.walkChildNodes(t,e),y=void 0}};var k=Object.defineProperty,V=g((t,e)=>k(t,"name",{value:e,configurable:!0}),"i");const W=V((t,e={})=>{const i={...A,...e.strategy},r=[],s=[];return i.walkNodes(i.getRootNode(t,e.fileName),a=>{if(i.isTaggedTemplate(a)){const n=i.getTaggedTemplateTemplate(a);s.push(n),r.push({parts:i.getTemplateParts(n),tag:i.getTagText(a)})}else i.isTemplate(a)&&!s.includes(a)&&r.push({parts:i.getTemplateParts(a)})}),r},"parseLiterals");var $=Object.defineProperty,C=g((t,e)=>$(t,"name",{value:e,configurable:!0}),"f");const S={One:"1",Two:"2",Zero:"0"},F=C(t=>{const e={[S.One]:{tidySelectors:!1,transform:void 0},[S.Two]:{tidySelectors:!1,transform:void 0},[S.Zero]:{}};if(t===void 0)return e;if(typeof t=="number"){const i=t.toString();return{...e,[i]:{...e[i]}}}return t},"optimizationLevelFrom"),P=C((t,e)=>{const i=/(:.+\((.*)\))\s*\{/g;let r;for(;(r=i.exec(t))!==null;){const s=r[1],a=r[2];if(!s||!a||!/\s/.test(a))continue;const n=a.replaceAll(/\s/g,""),o=s.replace(a,n),f=e.indexOf(o);if(f===-1)continue;const u=f+o.length;e=e.slice(0,Math.max(0,f))+s+e.slice(Math.max(0,u))}return e},"fixCleanCssTidySelectors"),R={},B={caseSensitive:!0,collapseWhitespace:!0,decodeEntities:!0,minifyCSS:R,minifyJS:!0,processConditionalComments:!0,removeAttributeQuotes:!1,removeComments:!0,removeEmptyAttributes:!0,removeScriptTypeAttributes:!0,removeStyleLinkTypeAttributes:!0,useShortDoctype:!0},x=C((t={})=>{const e=F(t.level),i=typeof t.level=="object"&&t.level[1]&&t.level[1].transform;return e[S.One].transform=(r,s)=>s.startsWith("@TEMPLATE_EXPRESSION")&&!s.endsWith(";")?s=`${s};`:i?i(r,s):s,{...t,level:e}},"adjustMinifyCSSOptions"),_={combineHTMLStrings(t,e){return t.map(i=>i.text).join(e)},getPlaceholder(t){let e="@TEMPLATE_EXPRESSION";for(;t.some(i=>i.text.includes(e+"();"));)e+="_";return e+"();"},minifyCSS(t,e={}){const i=x(e),r=new N(i).minify(t);if(r.errors&&r.errors.length>0)throw new Error(r.errors.join(`
|
|
2
|
+
|
|
3
|
+
`));return i.level[S.One].tidySelectors&&(r.styles=P(t,r.styles)),r.styles},async minifyHTML(t,e={}){let i;e.minifyCSS?i=e.minifyCSS!==!0&&typeof e.minifyCSS!="function"?{...e.minifyCSS}:{}:i=!1;let r=!1;i&&(r=x(i));let s=await j(t,{...e,minifyCSS:r});if(e.collapseWhitespace){const a=[...s.matchAll(/<svg/g)].reverse();for(const n of a){const o=n.index,f=s.indexOf("</svg",o);if(f===-1)continue;const u=s.slice(0,Math.max(0,o));let l=s.substring(o,f);const d=s.slice(Math.max(0,f));l=l.replaceAll(/\r?\n/g,""),s=u+l+d}}return r&&r.level[S.One].tidySelectors&&(s=P(t,s)),s},splitHTMLByPlaceholder(t,e){const i=t.split(e);if(e.endsWith(";")){const r=e.slice(0,Math.max(0,e.length-1));for(let s=i.length-1;s>=0;s--){const a=i[s];a!==void 0&&i.splice(s,1,...a.split(r))}}return i}};var G=Object.defineProperty,M=g((t,e)=>G(t,"name",{value:e,configurable:!0}),"l");const I=M((t,e)=>t.generateMap({file:`${e}.map`,hires:!0,source:e}),"defaultGenerateSourceMap"),X=M(t=>{const e=t.tag&&t.tag.toLowerCase();return!!e&&(e.includes("html")||e.includes("svg"))},"defaultShouldMinify"),Z=M(t=>!!t.tag&&t.tag.toLowerCase().includes("css"),"defaultShouldMinifyCSS"),z={ensureHTMLPartsValid(t,e){if(t.length!==e.length)throw new Error("splitHTMLByPlaceholder() must return same number of strings as template parts")},ensurePlaceholderValid(t){if(typeof t!="string"||t.length===0)throw new Error("getPlaceholder() must return a non-empty string")}};async function w(t,e={}){e.minifyOptions={...B,...e.minifyOptions},e.MagicString||(e.MagicString=H),e.parseLiterals||(e.parseLiterals=W),e.shouldMinify||(e.shouldMinify=X),e.shouldMinifyCSS||(e.shouldMinifyCSS=Z),e.parseLiteralsOptions={fileName:e.fileName,...e.parseLiteralsOptions};const i=e.parseLiterals(t,e.parseLiteralsOptions),r=e.strategy||_,{shouldMinify:s,shouldMinifyCSS:a}=e;let n;e.validate!==!1&&(n=e.validate||z);const o=new e.MagicString(t);for(const l of i){const d=s(l),O=!!r.minifyCSS&&a(l);if(d||O){const v=r.getPlaceholder(l.parts);n&&n.ensurePlaceholderValid(v);const T=r.combineHTMLStrings(l.parts,v);let h;if(O){const c=(e.minifyOptions||{}).minifyCSS;if(typeof c=="function"){const m=c(T);h=typeof m=="string"?m:await m}else if(c===!1)h=T;else{const m=typeof c=="object"?c:void 0;h=await r.minifyCSS(T,m)}}else h=await r.minifyHTML(T,e.minifyOptions);const L=r.splitHTMLByPlaceholder(h,v);n&&n.ensureHTMLPartsValid(l.parts,L),l.parts.forEach((c,m)=>{c.start<c.end&&L[m]!==void 0&&o.overwrite(c.start,c.end,L[m])})}}const f=o.toString();if(t===f)return;let u;return e.generateSourceMap!==!1&&(u=(e.generateSourceMap||I)(o,e.fileName??"")),{code:f,map:u}}g(w,"minifyHTMLLiterals");M(w,"minifyHTMLLiterals");var D=Object.defineProperty,J=g((t,e)=>D(t,"name",{value:e,configurable:!0}),"o");const te=J(({exclude:t,failOnError:e=!1,include:i,logger:r,minifyHTMLLiterals:s,options:a})=>{s||(s=w);const n=E(i,t),o=a||{};return{name:"packem:minify-html-literals",async transform(f,u){if(n(u))try{return await s(f,{...o,fileName:u})}catch(l){const d=l instanceof Error?l.message:l;e?this.error(d):r.warn({message:d,prefix:"plugin:minify-html-literals"})}}}},"minifyHTMLLiteralsPlugin");export{te as default,te as minifyHTMLLiteralsPlugin};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ported from https://github.com/lit/lit/tree/main/packages/labs/rollup-plugin-minify-html-literals
|
|
3
|
+
*
|
|
4
|
+
* BSD-3-Clause License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2024 Google LLC
|
|
7
|
+
*/
|
|
8
|
+
import type { SourceMapOptions } from "magic-string";
|
|
9
|
+
import type { Template, TemplatePart } from "./models.d.ts";
|
|
10
|
+
import type { ParseLiteralsOptions } from "./parse-literals.d.ts";
|
|
11
|
+
import { parseLiterals } from "./parse-literals.d.ts";
|
|
12
|
+
import type { Strategy } from "./strategy.d.ts";
|
|
13
|
+
import { defaultMinifyOptions } from "./strategy.d.ts";
|
|
14
|
+
/**
|
|
15
|
+
* Options for <code>minifyHTMLLiterals()</code>.
|
|
16
|
+
*/
|
|
17
|
+
export type Options = DefaultOptions | CustomOptions<unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Options for <code>minifyHTMLLiterals()</code>, using default html-minifier
|
|
20
|
+
* strategy.
|
|
21
|
+
*/
|
|
22
|
+
export interface DefaultOptions extends BaseOptions {
|
|
23
|
+
/**
|
|
24
|
+
* <code>html-minifier</code> options to use. Defaults to
|
|
25
|
+
* <code>defaultMinifyOptions</code>, for production-ready minification.
|
|
26
|
+
*/
|
|
27
|
+
minifyOptions?: Partial<typeof defaultMinifyOptions>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Options for <code>minifyHTMLLiterals()</code>, using a custom strategy.
|
|
31
|
+
*/
|
|
32
|
+
export interface CustomOptions<S extends Strategy | unknown> extends BaseOptions {
|
|
33
|
+
/**
|
|
34
|
+
* HTML minification options.
|
|
35
|
+
*/
|
|
36
|
+
minifyOptions?: S extends Strategy<infer O> ? Partial<O> : never;
|
|
37
|
+
/**
|
|
38
|
+
* Override the default strategy for how to minify HTML. The default is to
|
|
39
|
+
* use <code>html-minifier</code>.
|
|
40
|
+
*/
|
|
41
|
+
strategy: S;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Options for <code>minifyHTMLLiterals()</code>.
|
|
45
|
+
*/
|
|
46
|
+
export interface BaseOptions {
|
|
47
|
+
/**
|
|
48
|
+
* The name of the file. This is used to determine how to parse the source
|
|
49
|
+
* code and for source map filenames. It may be a base name, relative, or
|
|
50
|
+
* absolute path.
|
|
51
|
+
*/
|
|
52
|
+
fileName?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Override how source maps are generated. Set to false to disable source map
|
|
55
|
+
* generation.
|
|
56
|
+
* @param ms the MagicString instance with code modifications
|
|
57
|
+
* @param fileName the name or path of the file
|
|
58
|
+
* @returns a v3 SourceMap or undefined
|
|
59
|
+
*/
|
|
60
|
+
generateSourceMap?: ((ms: MagicStringLike, fileName: string) => SourceMap | undefined) | false;
|
|
61
|
+
/**
|
|
62
|
+
* The MagicString-like constructor to use. MagicString is used to replace
|
|
63
|
+
* strings and generate source maps.
|
|
64
|
+
*
|
|
65
|
+
* Override if you want to set your own version of MagicString or change how
|
|
66
|
+
* strings are overridden. Use <code>generateSourceMap</code> if you want to
|
|
67
|
+
* change how source maps are created.
|
|
68
|
+
*/
|
|
69
|
+
MagicString?: new (source: string) => MagicStringLike;
|
|
70
|
+
/**
|
|
71
|
+
* Override how template literals are parsed from a source string.
|
|
72
|
+
*/
|
|
73
|
+
parseLiterals?: typeof parseLiterals;
|
|
74
|
+
/**
|
|
75
|
+
* Options for <code>parseLiterals()</code>.
|
|
76
|
+
*/
|
|
77
|
+
parseLiteralsOptions?: Partial<ParseLiteralsOptions>;
|
|
78
|
+
/**
|
|
79
|
+
* Determines whether or not a template should be minified. The default is to
|
|
80
|
+
* minify all tagged template whose tag name contains "html" (case
|
|
81
|
+
* insensitive).
|
|
82
|
+
* @param template the template to check
|
|
83
|
+
* @returns true if the template should be minified
|
|
84
|
+
*/
|
|
85
|
+
shouldMinify?: (template: Template) => boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Determines whether or not a CSS template should be minified. The default is
|
|
88
|
+
* to minify all tagged template whose tag name contains "css" (case
|
|
89
|
+
* insensitive).
|
|
90
|
+
* @param template the template to check
|
|
91
|
+
* @returns true if the template should be minified
|
|
92
|
+
*/
|
|
93
|
+
shouldMinifyCSS?: (template: Template) => boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Override custom validation or set to false to disable validation. This is
|
|
96
|
+
* only useful when implementing your own strategy that may return
|
|
97
|
+
* unexpected results.
|
|
98
|
+
*/
|
|
99
|
+
validate?: Validation | false;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* A MagicString-like instance. <code>minify-html-literals</code> only uses a
|
|
103
|
+
* subset of the MagicString API to overwrite the source code and generate
|
|
104
|
+
* source maps.
|
|
105
|
+
*/
|
|
106
|
+
export interface MagicStringLike {
|
|
107
|
+
generateMap: (options?: Partial<SourceMapOptions>) => SourceMap;
|
|
108
|
+
overwrite: (start: number, end: number, content: string) => unknown;
|
|
109
|
+
toString: () => string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* A v3 SourceMap.
|
|
113
|
+
*
|
|
114
|
+
* <code>magic-string> incorrectly declares the SourceMap type with a version
|
|
115
|
+
* string instead of a number, so <code>minify-html-literals</code> declares
|
|
116
|
+
* its own type.
|
|
117
|
+
*/
|
|
118
|
+
export interface SourceMap {
|
|
119
|
+
file?: string;
|
|
120
|
+
mappings: string;
|
|
121
|
+
names: string[];
|
|
122
|
+
sources: string[];
|
|
123
|
+
sourcesContent?: string[];
|
|
124
|
+
toString: () => string;
|
|
125
|
+
toUrl: () => string;
|
|
126
|
+
version: number;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Validation that is executed when minifying HTML to ensure there are no
|
|
130
|
+
* unexpected errors. This is to alleviate hard-to-troubleshoot errors such as
|
|
131
|
+
* undefined errors.
|
|
132
|
+
*/
|
|
133
|
+
export interface Validation {
|
|
134
|
+
/**
|
|
135
|
+
* Throws an error if <code>strategy.splitHTMLByPlaceholder()</code> does not
|
|
136
|
+
* return an HTML part string for each template part.
|
|
137
|
+
* @param parts the template parts that generated the strings
|
|
138
|
+
* @param htmlParts the split HTML strings
|
|
139
|
+
*/
|
|
140
|
+
ensureHTMLPartsValid: (parts: TemplatePart[], htmlParts: string[]) => void;
|
|
141
|
+
/**
|
|
142
|
+
* Throws an error if <code>strategy.getPlaceholder()</code> does not return
|
|
143
|
+
* a valid placeholder string.
|
|
144
|
+
* @param placeholder the placeholder to check
|
|
145
|
+
*/
|
|
146
|
+
ensurePlaceholderValid: (placeholder: unknown) => void;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The result of a call to <code>minifyHTMLLiterals()</code>.
|
|
150
|
+
*/
|
|
151
|
+
export interface Result {
|
|
152
|
+
/**
|
|
153
|
+
* The minified code.
|
|
154
|
+
*/
|
|
155
|
+
code: string;
|
|
156
|
+
/**
|
|
157
|
+
* Optional v3 SourceMap for the code.
|
|
158
|
+
*/
|
|
159
|
+
map: SourceMap | undefined;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The default method to generate a SourceMap. It will generate the SourceMap
|
|
163
|
+
* from the provided MagicString instance using "fileName.map" as the file and
|
|
164
|
+
* "fileName" as the source.
|
|
165
|
+
* @param ms the MagicString instance with code modifications
|
|
166
|
+
* @param fileName the name of the source file
|
|
167
|
+
* @returns a v3 SourceMap
|
|
168
|
+
*/
|
|
169
|
+
export declare const defaultGenerateSourceMap: (ms: MagicStringLike, fileName: string) => SourceMap;
|
|
170
|
+
/**
|
|
171
|
+
* The default method to determine whether or not to minify a template. It will
|
|
172
|
+
* return true for all tagged templates whose tag name contains "html" (case
|
|
173
|
+
* insensitive).
|
|
174
|
+
* @param template the template to check
|
|
175
|
+
* @returns true if the template should be minified
|
|
176
|
+
*/
|
|
177
|
+
export declare const defaultShouldMinify: (template: Template) => boolean;
|
|
178
|
+
/**
|
|
179
|
+
* The default method to determine whether or not to minify a CSS template. It
|
|
180
|
+
* will return true for all tagged templates whose tag name contains "css" (case
|
|
181
|
+
* insensitive).
|
|
182
|
+
* @param template the template to check
|
|
183
|
+
* @returns true if the template should be minified
|
|
184
|
+
*/
|
|
185
|
+
export declare const defaultShouldMinifyCSS: (template: Template) => boolean;
|
|
186
|
+
export declare const defaultValidation: Validation;
|
|
187
|
+
/**
|
|
188
|
+
* Minifies all HTML template literals in the provided source string.
|
|
189
|
+
* @param source the source code
|
|
190
|
+
* @param options minification options
|
|
191
|
+
* @returns the minified code, or null if no minification occurred.
|
|
192
|
+
*/
|
|
193
|
+
export declare function minifyHTMLLiterals(source: string, options?: DefaultOptions): Promise<Result | null>;
|
|
194
|
+
/**
|
|
195
|
+
* Minifies all HTML template literals in the provided source string.
|
|
196
|
+
* @param source the source code
|
|
197
|
+
* @param options minification options
|
|
198
|
+
* @returns the minified code, or null if no minification occurred.
|
|
199
|
+
*/
|
|
200
|
+
export declare function minifyHTMLLiterals<S extends Strategy>(source: string, options?: CustomOptions<S>): Promise<Result | undefined>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ported from https://github.com/lit/lit/tree/main/packages/labs/rollup-plugin-minify-html-literals
|
|
3
|
+
*
|
|
4
|
+
* BSD-3-Clause License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2024 Google LLC
|
|
7
|
+
*/
|
|
8
|
+
export interface Template {
|
|
9
|
+
parts: TemplatePart[];
|
|
10
|
+
tag?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface TemplatePart {
|
|
13
|
+
end: number;
|
|
14
|
+
start: number;
|
|
15
|
+
text: string;
|
|
16
|
+
}
|
|
17
|
+
export interface Strategy<N = unknown> {
|
|
18
|
+
getRootNode: (source: string, fileName?: string) => N;
|
|
19
|
+
getTaggedTemplateTemplate: (node: N) => unknown;
|
|
20
|
+
getTagText: (node: N) => string;
|
|
21
|
+
getTemplateParts: (node: N) => TemplatePart[];
|
|
22
|
+
isTaggedTemplate: (node: N) => boolean;
|
|
23
|
+
isTemplate: (node: N) => boolean;
|
|
24
|
+
walkNodes: (parent: N, visit: (child: N) => void) => void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ported from https://github.com/lit/lit/tree/main/packages/labs/rollup-plugin-minify-html-literals
|
|
3
|
+
*
|
|
4
|
+
* BSD-3-Clause License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2024 Google LLC
|
|
7
|
+
*/
|
|
8
|
+
import type { Strategy, Template } from "./models.d.ts";
|
|
9
|
+
export interface ParseLiteralsOptions {
|
|
10
|
+
fileName?: string;
|
|
11
|
+
strategy?: Partial<Strategy<unknown>>;
|
|
12
|
+
}
|
|
13
|
+
export declare const parseLiterals: (source: string, options?: ParseLiteralsOptions) => Template[];
|