@tanstack/router-utils
Advanced tools
| //#region \0rolldown/runtime.js | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { | ||
| key = keys[i]; | ||
| if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { | ||
| get: ((k) => from[k]).bind(null, key), | ||
| enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable | ||
| }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { | ||
| value: mod, | ||
| enumerable: true | ||
| }) : target, mod)); | ||
| //#endregion | ||
| exports.__toESM = __toESM; |
+91
-83
@@ -1,91 +0,98 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
| const parser = require("@babel/parser"); | ||
| const _generate = require("@babel/generator"); | ||
| const t = require("@babel/types"); | ||
| const babelDeadCodeElimination = require("babel-dead-code-elimination"); | ||
| function _interopNamespaceDefault(e) { | ||
| const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } }); | ||
| if (e) { | ||
| for (const k in e) { | ||
| if (k !== "default") { | ||
| const d = Object.getOwnPropertyDescriptor(e, k); | ||
| Object.defineProperty(n, k, d.get ? d : { | ||
| enumerable: true, | ||
| get: () => e[k] | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| n.default = e; | ||
| return Object.freeze(n); | ||
| } | ||
| const t__namespace = /* @__PURE__ */ _interopNamespaceDefault(t); | ||
| const require_runtime = require("./_virtual/_rolldown/runtime.cjs"); | ||
| let _babel_parser = require("@babel/parser"); | ||
| let _babel_generator = require("@babel/generator"); | ||
| _babel_generator = require_runtime.__toESM(_babel_generator); | ||
| let _babel_types = require("@babel/types"); | ||
| _babel_types = require_runtime.__toESM(_babel_types); | ||
| let babel_dead_code_elimination = require("babel-dead-code-elimination"); | ||
| //#region src/ast.ts | ||
| function parseAst({ code, ...opts }) { | ||
| return parser.parse(code, { | ||
| plugins: ["jsx", "typescript", "explicitResourceManagement"], | ||
| sourceType: "module", | ||
| ...opts | ||
| }); | ||
| return (0, _babel_parser.parse)(code, { | ||
| plugins: [ | ||
| "jsx", | ||
| "typescript", | ||
| "explicitResourceManagement" | ||
| ], | ||
| sourceType: "module", | ||
| ...opts | ||
| }); | ||
| } | ||
| let generate = _generate; | ||
| if ("default" in generate) { | ||
| generate = generate.default; | ||
| } | ||
| var generate = _babel_generator.default; | ||
| if ("default" in generate) generate = generate.default; | ||
| function generateFromAst(ast, opts) { | ||
| return generate( | ||
| ast, | ||
| opts ? { importAttributesKeyword: "with", sourceMaps: true, ...opts } : void 0 | ||
| ); | ||
| return generate(ast, opts ? { | ||
| importAttributesKeyword: "with", | ||
| sourceMaps: true, | ||
| ...opts | ||
| } : void 0); | ||
| } | ||
| /** | ||
| * Strips TypeScript type-only exports and imports from an AST. | ||
| * | ||
| * This is necessary because babel-dead-code-elimination doesn't handle | ||
| * TypeScript type exports/imports. When a type export references an import | ||
| * that pulls in server-only code, the dead code elimination won't remove | ||
| * that import because it sees the type as still referencing it. | ||
| * | ||
| * This function removes: | ||
| * - `export type Foo = ...` | ||
| * - `export interface Foo { ... }` | ||
| * - `export type { Foo } from './module'` | ||
| * - `export type * from './module'` | ||
| * - Type specifiers in mixed exports: `export { value, type Foo }` -> `export { value }` | ||
| * - `import type { Foo } from './module'` | ||
| * - Type specifiers in mixed imports: `import { value, type Foo } from './module'` -> `import { value }` | ||
| * | ||
| * Note: Non-exported type/interface declarations are preserved as they may be | ||
| * used as type annotations within the code. | ||
| * | ||
| * @param ast - The Babel AST (or ParseResult) to mutate | ||
| */ | ||
| function stripTypeExports(ast) { | ||
| ast.program.body = ast.program.body.filter((node) => { | ||
| if (t__namespace.isExportNamedDeclaration(node)) { | ||
| if (node.exportKind === "type") { | ||
| return false; | ||
| } | ||
| if (node.specifiers.length > 0) { | ||
| node.specifiers = node.specifiers.filter((specifier) => { | ||
| if (t__namespace.isExportSpecifier(specifier)) { | ||
| return specifier.exportKind !== "type"; | ||
| } | ||
| return true; | ||
| }); | ||
| if (node.specifiers.length === 0 && !node.declaration) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| if (t__namespace.isExportAllDeclaration(node)) { | ||
| if (node.exportKind === "type") { | ||
| return false; | ||
| } | ||
| } | ||
| if (t__namespace.isImportDeclaration(node)) { | ||
| if (node.importKind === "type") { | ||
| return false; | ||
| } | ||
| if (node.specifiers.length > 0) { | ||
| node.specifiers = node.specifiers.filter((specifier) => { | ||
| if (t__namespace.isImportSpecifier(specifier)) { | ||
| return specifier.importKind !== "type"; | ||
| } | ||
| return true; | ||
| }); | ||
| if (node.specifiers.length === 0) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| return true; | ||
| }); | ||
| ast.program.body = ast.program.body.filter((node) => { | ||
| if (_babel_types.isExportNamedDeclaration(node)) { | ||
| if (node.exportKind === "type") return false; | ||
| if (node.specifiers.length > 0) { | ||
| node.specifiers = node.specifiers.filter((specifier) => { | ||
| if (_babel_types.isExportSpecifier(specifier)) return specifier.exportKind !== "type"; | ||
| return true; | ||
| }); | ||
| if (node.specifiers.length === 0 && !node.declaration) return false; | ||
| } | ||
| } | ||
| if (_babel_types.isExportAllDeclaration(node)) { | ||
| if (node.exportKind === "type") return false; | ||
| } | ||
| if (_babel_types.isImportDeclaration(node)) { | ||
| if (node.importKind === "type") return false; | ||
| if (node.specifiers.length > 0) { | ||
| node.specifiers = node.specifiers.filter((specifier) => { | ||
| if (_babel_types.isImportSpecifier(specifier)) return specifier.importKind !== "type"; | ||
| return true; | ||
| }); | ||
| if (node.specifiers.length === 0) return false; | ||
| } | ||
| } | ||
| return true; | ||
| }); | ||
| } | ||
| /** | ||
| * Performs dead code elimination on the AST, with TypeScript type stripping. | ||
| * | ||
| * This is a wrapper around babel-dead-code-elimination that first strips | ||
| * TypeScript type-only exports and imports. This is necessary because | ||
| * babel-dead-code-elimination doesn't handle type exports, which can cause | ||
| * imports to be retained when they're only referenced by type exports. | ||
| * | ||
| * @param ast - The Babel AST to mutate | ||
| * @param candidates - Optional set of identifier paths to consider for removal. | ||
| * If provided, only these identifiers will be candidates for removal. | ||
| * This should be the result of `findReferencedIdentifiers(ast)` called | ||
| * before any AST transformations. | ||
| */ | ||
| function deadCodeElimination(ast, candidates) { | ||
| stripTypeExports(ast); | ||
| babelDeadCodeElimination.deadCodeElimination(ast, candidates); | ||
| stripTypeExports(ast); | ||
| (0, babel_dead_code_elimination.deadCodeElimination)(ast, candidates); | ||
| } | ||
| Object.defineProperty(exports, "findReferencedIdentifiers", { | ||
| enumerable: true, | ||
| get: () => babelDeadCodeElimination.findReferencedIdentifiers | ||
| }); | ||
| //#endregion | ||
| exports.deadCodeElimination = deadCodeElimination; | ||
@@ -95,2 +102,3 @@ exports.generateFromAst = generateFromAst; | ||
| exports.stripTypeExports = stripTypeExports; | ||
| //# sourceMappingURL=ast.cjs.map | ||
| //# sourceMappingURL=ast.cjs.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"ast.cjs","sources":["../../src/ast.ts"],"sourcesContent":["import { parse } from '@babel/parser'\nimport _generate from '@babel/generator'\nimport * as t from '@babel/types'\nimport {\n deadCodeElimination as _deadCodeElimination,\n findReferencedIdentifiers,\n} from 'babel-dead-code-elimination'\nimport type { GeneratorOptions, GeneratorResult } from '@babel/generator'\nimport type { ParseResult, ParserOptions } from '@babel/parser'\nimport type * as _babel_types from '@babel/types'\n\nexport type ParseAstOptions = ParserOptions & {\n code: string\n}\n\nexport type ParseAstResult = ParseResult<_babel_types.File>\nexport function parseAst({ code, ...opts }: ParseAstOptions): ParseAstResult {\n return parse(code, {\n plugins: ['jsx', 'typescript', 'explicitResourceManagement'],\n sourceType: 'module',\n ...opts,\n })\n}\n\nlet generate = _generate\n\nif ('default' in generate) {\n generate = generate.default as typeof generate\n}\ntype GenerateFromAstOptions = GeneratorOptions &\n Required<Pick<GeneratorOptions, 'sourceFileName' | 'filename'>>\nexport function generateFromAst(\n ast: _babel_types.Node,\n opts?: GenerateFromAstOptions,\n): GeneratorResult {\n return generate(\n ast,\n opts\n ? { importAttributesKeyword: 'with', sourceMaps: true, ...opts }\n : undefined,\n )\n}\nexport type { GeneratorResult } from '@babel/generator'\n\n/**\n * Strips TypeScript type-only exports and imports from an AST.\n *\n * This is necessary because babel-dead-code-elimination doesn't handle\n * TypeScript type exports/imports. When a type export references an import\n * that pulls in server-only code, the dead code elimination won't remove\n * that import because it sees the type as still referencing it.\n *\n * This function removes:\n * - `export type Foo = ...`\n * - `export interface Foo { ... }`\n * - `export type { Foo } from './module'`\n * - `export type * from './module'`\n * - Type specifiers in mixed exports: `export { value, type Foo }` -> `export { value }`\n * - `import type { Foo } from './module'`\n * - Type specifiers in mixed imports: `import { value, type Foo } from './module'` -> `import { value }`\n *\n * Note: Non-exported type/interface declarations are preserved as they may be\n * used as type annotations within the code.\n *\n * @param ast - The Babel AST (or ParseResult) to mutate\n */\nexport function stripTypeExports(ast: ParseResult<_babel_types.File>): void {\n // Filter the program body to remove type-only nodes\n ast.program.body = ast.program.body.filter((node) => {\n // Handle export declarations\n if (t.isExportNamedDeclaration(node)) {\n // Remove entire export if it's a type-only export\n // e.g., `export type Foo = string`, `export interface Bar {}`, `export type { X } from './y'`\n if (node.exportKind === 'type') {\n return false\n }\n\n // For value exports with mixed specifiers, filter out type-only specifiers\n // e.g., `export { value, type TypeOnly }` -> `export { value }`\n if (node.specifiers.length > 0) {\n node.specifiers = node.specifiers.filter((specifier) => {\n if (t.isExportSpecifier(specifier)) {\n return specifier.exportKind !== 'type'\n }\n return true\n })\n\n // If all specifiers were removed, remove the entire export declaration\n // (unless it has a declaration like `export const x = 1`)\n if (node.specifiers.length === 0 && !node.declaration) {\n return false\n }\n }\n }\n\n // Handle type-only export-all declarations\n // e.g., `export type * from './module'`\n if (t.isExportAllDeclaration(node)) {\n if (node.exportKind === 'type') {\n return false\n }\n }\n\n // Handle import declarations\n if (t.isImportDeclaration(node)) {\n // Remove entire import if it's a type-only import\n // e.g., `import type { Foo } from './module'`\n if (node.importKind === 'type') {\n return false\n }\n\n // For value imports with mixed specifiers, filter out type-only specifiers\n // e.g., `import { value, type TypeOnly } from './module'` -> `import { value }`\n if (node.specifiers.length > 0) {\n node.specifiers = node.specifiers.filter((specifier) => {\n if (t.isImportSpecifier(specifier)) {\n return specifier.importKind !== 'type'\n }\n return true\n })\n\n // If all specifiers were removed, remove the entire import declaration\n if (node.specifiers.length === 0) {\n return false\n }\n }\n }\n\n return true\n })\n}\n\n// Re-export findReferencedIdentifiers from babel-dead-code-elimination\nexport { findReferencedIdentifiers }\n\n/**\n * Performs dead code elimination on the AST, with TypeScript type stripping.\n *\n * This is a wrapper around babel-dead-code-elimination that first strips\n * TypeScript type-only exports and imports. This is necessary because\n * babel-dead-code-elimination doesn't handle type exports, which can cause\n * imports to be retained when they're only referenced by type exports.\n *\n * @param ast - The Babel AST to mutate\n * @param candidates - Optional set of identifier paths to consider for removal.\n * If provided, only these identifiers will be candidates for removal.\n * This should be the result of `findReferencedIdentifiers(ast)` called\n * before any AST transformations.\n */\nexport function deadCodeElimination(\n ast: ParseResult<_babel_types.File>,\n candidates?: ReturnType<typeof findReferencedIdentifiers>,\n): void {\n // First strip TypeScript type-only exports and imports\n stripTypeExports(ast)\n\n // Then run the original dead code elimination\n _deadCodeElimination(ast, candidates)\n}\n"],"names":["parse","t","_deadCodeElimination"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgBO,SAAS,SAAS,EAAE,MAAM,GAAG,QAAyC;AAC3E,SAAOA,OAAAA,MAAM,MAAM;AAAA,IACjB,SAAS,CAAC,OAAO,cAAc,4BAA4B;AAAA,IAC3D,YAAY;AAAA,IACZ,GAAG;AAAA,EAAA,CACJ;AACH;AAEA,IAAI,WAAW;AAEf,IAAI,aAAa,UAAU;AACzB,aAAW,SAAS;AACtB;AAGO,SAAS,gBACd,KACA,MACiB;AACjB,SAAO;AAAA,IACL;AAAA,IACA,OACI,EAAE,yBAAyB,QAAQ,YAAY,MAAM,GAAG,SACxD;AAAA,EAAA;AAER;AAyBO,SAAS,iBAAiB,KAA2C;AAE1E,MAAI,QAAQ,OAAO,IAAI,QAAQ,KAAK,OAAO,CAAC,SAAS;AAEnD,QAAIC,aAAE,yBAAyB,IAAI,GAAG;AAGpC,UAAI,KAAK,eAAe,QAAQ;AAC9B,eAAO;AAAA,MACT;AAIA,UAAI,KAAK,WAAW,SAAS,GAAG;AAC9B,aAAK,aAAa,KAAK,WAAW,OAAO,CAAC,cAAc;AACtD,cAAIA,aAAE,kBAAkB,SAAS,GAAG;AAClC,mBAAO,UAAU,eAAe;AAAA,UAClC;AACA,iBAAO;AAAA,QACT,CAAC;AAID,YAAI,KAAK,WAAW,WAAW,KAAK,CAAC,KAAK,aAAa;AACrD,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAIA,QAAIA,aAAE,uBAAuB,IAAI,GAAG;AAClC,UAAI,KAAK,eAAe,QAAQ;AAC9B,eAAO;AAAA,MACT;AAAA,IACF;AAGA,QAAIA,aAAE,oBAAoB,IAAI,GAAG;AAG/B,UAAI,KAAK,eAAe,QAAQ;AAC9B,eAAO;AAAA,MACT;AAIA,UAAI,KAAK,WAAW,SAAS,GAAG;AAC9B,aAAK,aAAa,KAAK,WAAW,OAAO,CAAC,cAAc;AACtD,cAAIA,aAAE,kBAAkB,SAAS,GAAG;AAClC,mBAAO,UAAU,eAAe;AAAA,UAClC;AACA,iBAAO;AAAA,QACT,CAAC;AAGD,YAAI,KAAK,WAAW,WAAW,GAAG;AAChC,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT,CAAC;AACH;AAmBO,SAAS,oBACd,KACA,YACM;AAEN,mBAAiB,GAAG;AAGpBC,2BAAAA,oBAAqB,KAAK,UAAU;AACtC;;;;;;;;;"} | ||
| {"version":3,"file":"ast.cjs","names":[],"sources":["../../src/ast.ts"],"sourcesContent":["import { parse } from '@babel/parser'\nimport _generate from '@babel/generator'\nimport * as t from '@babel/types'\nimport {\n deadCodeElimination as _deadCodeElimination,\n findReferencedIdentifiers,\n} from 'babel-dead-code-elimination'\nimport type { GeneratorOptions, GeneratorResult } from '@babel/generator'\nimport type { ParseResult, ParserOptions } from '@babel/parser'\nimport type * as _babel_types from '@babel/types'\n\nexport type ParseAstOptions = ParserOptions & {\n code: string\n}\n\nexport type ParseAstResult = ParseResult<_babel_types.File>\nexport function parseAst({ code, ...opts }: ParseAstOptions): ParseAstResult {\n return parse(code, {\n plugins: ['jsx', 'typescript', 'explicitResourceManagement'],\n sourceType: 'module',\n ...opts,\n })\n}\n\nlet generate = _generate\n\nif ('default' in generate) {\n generate = generate.default as typeof generate\n}\ntype GenerateFromAstOptions = GeneratorOptions &\n Required<Pick<GeneratorOptions, 'sourceFileName' | 'filename'>>\nexport function generateFromAst(\n ast: _babel_types.Node,\n opts?: GenerateFromAstOptions,\n): GeneratorResult {\n return generate(\n ast,\n opts\n ? { importAttributesKeyword: 'with', sourceMaps: true, ...opts }\n : undefined,\n )\n}\nexport type { GeneratorResult } from '@babel/generator'\n\n/**\n * Strips TypeScript type-only exports and imports from an AST.\n *\n * This is necessary because babel-dead-code-elimination doesn't handle\n * TypeScript type exports/imports. When a type export references an import\n * that pulls in server-only code, the dead code elimination won't remove\n * that import because it sees the type as still referencing it.\n *\n * This function removes:\n * - `export type Foo = ...`\n * - `export interface Foo { ... }`\n * - `export type { Foo } from './module'`\n * - `export type * from './module'`\n * - Type specifiers in mixed exports: `export { value, type Foo }` -> `export { value }`\n * - `import type { Foo } from './module'`\n * - Type specifiers in mixed imports: `import { value, type Foo } from './module'` -> `import { value }`\n *\n * Note: Non-exported type/interface declarations are preserved as they may be\n * used as type annotations within the code.\n *\n * @param ast - The Babel AST (or ParseResult) to mutate\n */\nexport function stripTypeExports(ast: ParseResult<_babel_types.File>): void {\n // Filter the program body to remove type-only nodes\n ast.program.body = ast.program.body.filter((node) => {\n // Handle export declarations\n if (t.isExportNamedDeclaration(node)) {\n // Remove entire export if it's a type-only export\n // e.g., `export type Foo = string`, `export interface Bar {}`, `export type { X } from './y'`\n if (node.exportKind === 'type') {\n return false\n }\n\n // For value exports with mixed specifiers, filter out type-only specifiers\n // e.g., `export { value, type TypeOnly }` -> `export { value }`\n if (node.specifiers.length > 0) {\n node.specifiers = node.specifiers.filter((specifier) => {\n if (t.isExportSpecifier(specifier)) {\n return specifier.exportKind !== 'type'\n }\n return true\n })\n\n // If all specifiers were removed, remove the entire export declaration\n // (unless it has a declaration like `export const x = 1`)\n if (node.specifiers.length === 0 && !node.declaration) {\n return false\n }\n }\n }\n\n // Handle type-only export-all declarations\n // e.g., `export type * from './module'`\n if (t.isExportAllDeclaration(node)) {\n if (node.exportKind === 'type') {\n return false\n }\n }\n\n // Handle import declarations\n if (t.isImportDeclaration(node)) {\n // Remove entire import if it's a type-only import\n // e.g., `import type { Foo } from './module'`\n if (node.importKind === 'type') {\n return false\n }\n\n // For value imports with mixed specifiers, filter out type-only specifiers\n // e.g., `import { value, type TypeOnly } from './module'` -> `import { value }`\n if (node.specifiers.length > 0) {\n node.specifiers = node.specifiers.filter((specifier) => {\n if (t.isImportSpecifier(specifier)) {\n return specifier.importKind !== 'type'\n }\n return true\n })\n\n // If all specifiers were removed, remove the entire import declaration\n if (node.specifiers.length === 0) {\n return false\n }\n }\n }\n\n return true\n })\n}\n\n// Re-export findReferencedIdentifiers from babel-dead-code-elimination\nexport { findReferencedIdentifiers }\n\n/**\n * Performs dead code elimination on the AST, with TypeScript type stripping.\n *\n * This is a wrapper around babel-dead-code-elimination that first strips\n * TypeScript type-only exports and imports. This is necessary because\n * babel-dead-code-elimination doesn't handle type exports, which can cause\n * imports to be retained when they're only referenced by type exports.\n *\n * @param ast - The Babel AST to mutate\n * @param candidates - Optional set of identifier paths to consider for removal.\n * If provided, only these identifiers will be candidates for removal.\n * This should be the result of `findReferencedIdentifiers(ast)` called\n * before any AST transformations.\n */\nexport function deadCodeElimination(\n ast: ParseResult<_babel_types.File>,\n candidates?: ReturnType<typeof findReferencedIdentifiers>,\n): void {\n // First strip TypeScript type-only exports and imports\n stripTypeExports(ast)\n\n // Then run the original dead code elimination\n _deadCodeElimination(ast, candidates)\n}\n"],"mappings":";;;;;;;;AAgBA,SAAgB,SAAS,EAAE,MAAM,GAAG,QAAyC;AAC3E,SAAA,GAAA,cAAA,OAAa,MAAM;EACjB,SAAS;GAAC;GAAO;GAAc;GAA6B;EAC5D,YAAY;EACZ,GAAG;EACJ,CAAC;;AAGJ,IAAI,WAAW,iBAAA;AAEf,IAAI,aAAa,SACf,YAAW,SAAS;AAItB,SAAgB,gBACd,KACA,MACiB;AACjB,QAAO,SACL,KACA,OACI;EAAE,yBAAyB;EAAQ,YAAY;EAAM,GAAG;EAAM,GAC9D,KAAA,EACL;;;;;;;;;;;;;;;;;;;;;;;;AA0BH,SAAgB,iBAAiB,KAA2C;AAE1E,KAAI,QAAQ,OAAO,IAAI,QAAQ,KAAK,QAAQ,SAAS;AAEnD,MAAI,aAAE,yBAAyB,KAAK,EAAE;AAGpC,OAAI,KAAK,eAAe,OACtB,QAAO;AAKT,OAAI,KAAK,WAAW,SAAS,GAAG;AAC9B,SAAK,aAAa,KAAK,WAAW,QAAQ,cAAc;AACtD,SAAI,aAAE,kBAAkB,UAAU,CAChC,QAAO,UAAU,eAAe;AAElC,YAAO;MACP;AAIF,QAAI,KAAK,WAAW,WAAW,KAAK,CAAC,KAAK,YACxC,QAAO;;;AAOb,MAAI,aAAE,uBAAuB,KAAK;OAC5B,KAAK,eAAe,OACtB,QAAO;;AAKX,MAAI,aAAE,oBAAoB,KAAK,EAAE;AAG/B,OAAI,KAAK,eAAe,OACtB,QAAO;AAKT,OAAI,KAAK,WAAW,SAAS,GAAG;AAC9B,SAAK,aAAa,KAAK,WAAW,QAAQ,cAAc;AACtD,SAAI,aAAE,kBAAkB,UAAU,CAChC,QAAO,UAAU,eAAe;AAElC,YAAO;MACP;AAGF,QAAI,KAAK,WAAW,WAAW,EAC7B,QAAO;;;AAKb,SAAO;GACP;;;;;;;;;;;;;;;;AAoBJ,SAAgB,oBACd,KACA,YACM;AAEN,kBAAiB,IAAI;AAGrB,EAAA,GAAA,4BAAA,qBAAqB,KAAK,WAAW"} |
@@ -1,30 +0,24 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
| const promises = require("node:fs/promises"); | ||
| const pathe = require("pathe"); | ||
| const tinyglobby = require("tinyglobby"); | ||
| function copyFilesPlugin({ | ||
| fromDir, | ||
| toDir, | ||
| pattern = "**" | ||
| }) { | ||
| return { | ||
| name: "copy-files", | ||
| async writeBundle() { | ||
| const entries = await tinyglobby.glob(pattern, { cwd: fromDir }); | ||
| if (entries.length === 0) { | ||
| throw new Error( | ||
| `No files found matching pattern "${pattern}" in directory "${fromDir}"` | ||
| ); | ||
| } | ||
| for (const entry of entries) { | ||
| const srcPath = pathe.join(fromDir, entry); | ||
| const destPath = pathe.join(toDir, entry); | ||
| await promises.mkdir(pathe.dirname(destPath), { recursive: true }); | ||
| await promises.copyFile(srcPath, destPath); | ||
| } | ||
| } | ||
| }; | ||
| require("./_virtual/_rolldown/runtime.cjs"); | ||
| let node_fs_promises = require("node:fs/promises"); | ||
| let pathe = require("pathe"); | ||
| let tinyglobby = require("tinyglobby"); | ||
| //#region src/copy-files-plugin.ts | ||
| function copyFilesPlugin({ fromDir, toDir, pattern = "**" }) { | ||
| return { | ||
| name: "copy-files", | ||
| async writeBundle() { | ||
| const entries = await (0, tinyglobby.glob)(pattern, { cwd: fromDir }); | ||
| if (entries.length === 0) throw new Error(`No files found matching pattern "${pattern}" in directory "${fromDir}"`); | ||
| for (const entry of entries) { | ||
| const srcPath = (0, pathe.join)(fromDir, entry); | ||
| const destPath = (0, pathe.join)(toDir, entry); | ||
| await (0, node_fs_promises.mkdir)((0, pathe.dirname)(destPath), { recursive: true }); | ||
| await (0, node_fs_promises.copyFile)(srcPath, destPath); | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| //#endregion | ||
| exports.copyFilesPlugin = copyFilesPlugin; | ||
| //# sourceMappingURL=copy-files-plugin.cjs.map | ||
| //# sourceMappingURL=copy-files-plugin.cjs.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"copy-files-plugin.cjs","sources":["../../src/copy-files-plugin.ts"],"sourcesContent":["import { copyFile, mkdir } from 'node:fs/promises'\nimport { dirname, join } from 'pathe'\nimport { glob } from 'tinyglobby'\nimport type { Plugin } from 'vite'\n\nexport function copyFilesPlugin({\n fromDir,\n toDir,\n pattern = '**',\n}: {\n pattern?: string | Array<string>\n fromDir: string\n toDir: string\n}): Plugin {\n return {\n name: 'copy-files',\n async writeBundle() {\n const entries = await glob(pattern, { cwd: fromDir })\n if (entries.length === 0) {\n throw new Error(\n `No files found matching pattern \"${pattern}\" in directory \"${fromDir}\"`,\n )\n }\n\n for (const entry of entries) {\n const srcPath = join(fromDir, entry)\n const destPath = join(toDir, entry)\n // Ensure the destination directory exists\n await mkdir(dirname(destPath), { recursive: true })\n await copyFile(srcPath, destPath)\n }\n },\n }\n}\n"],"names":["glob","join","mkdir","dirname","copyFile"],"mappings":";;;;;AAKO,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA,UAAU;AACZ,GAIW;AACT,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,cAAc;AAClB,YAAM,UAAU,MAAMA,WAAAA,KAAK,SAAS,EAAE,KAAK,SAAS;AACpD,UAAI,QAAQ,WAAW,GAAG;AACxB,cAAM,IAAI;AAAA,UACR,oCAAoC,OAAO,mBAAmB,OAAO;AAAA,QAAA;AAAA,MAEzE;AAEA,iBAAW,SAAS,SAAS;AAC3B,cAAM,UAAUC,MAAAA,KAAK,SAAS,KAAK;AACnC,cAAM,WAAWA,MAAAA,KAAK,OAAO,KAAK;AAElC,cAAMC,SAAAA,MAAMC,MAAAA,QAAQ,QAAQ,GAAG,EAAE,WAAW,MAAM;AAClD,cAAMC,SAAAA,SAAS,SAAS,QAAQ;AAAA,MAClC;AAAA,IACF;AAAA,EAAA;AAEJ;;"} | ||
| {"version":3,"file":"copy-files-plugin.cjs","names":[],"sources":["../../src/copy-files-plugin.ts"],"sourcesContent":["import { copyFile, mkdir } from 'node:fs/promises'\nimport { dirname, join } from 'pathe'\nimport { glob } from 'tinyglobby'\nimport type { Plugin } from 'vite'\n\nexport function copyFilesPlugin({\n fromDir,\n toDir,\n pattern = '**',\n}: {\n pattern?: string | Array<string>\n fromDir: string\n toDir: string\n}): Plugin {\n return {\n name: 'copy-files',\n async writeBundle() {\n const entries = await glob(pattern, { cwd: fromDir })\n if (entries.length === 0) {\n throw new Error(\n `No files found matching pattern \"${pattern}\" in directory \"${fromDir}\"`,\n )\n }\n\n for (const entry of entries) {\n const srcPath = join(fromDir, entry)\n const destPath = join(toDir, entry)\n // Ensure the destination directory exists\n await mkdir(dirname(destPath), { recursive: true })\n await copyFile(srcPath, destPath)\n }\n },\n }\n}\n"],"mappings":";;;;;AAKA,SAAgB,gBAAgB,EAC9B,SACA,OACA,UAAU,QAKD;AACT,QAAO;EACL,MAAM;EACN,MAAM,cAAc;GAClB,MAAM,UAAU,OAAA,GAAA,WAAA,MAAW,SAAS,EAAE,KAAK,SAAS,CAAC;AACrD,OAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MACR,oCAAoC,QAAQ,kBAAkB,QAAQ,GACvE;AAGH,QAAK,MAAM,SAAS,SAAS;IAC3B,MAAM,WAAA,GAAA,MAAA,MAAe,SAAS,MAAM;IACpC,MAAM,YAAA,GAAA,MAAA,MAAgB,OAAO,MAAM;AAEnC,WAAA,GAAA,iBAAA,QAAA,GAAA,MAAA,SAAoB,SAAS,EAAE,EAAE,WAAW,MAAM,CAAC;AACnD,WAAA,GAAA,iBAAA,UAAe,SAAS,SAAS;;;EAGtC"} |
+12
-16
@@ -1,17 +0,13 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
| const ast = require("./ast.cjs"); | ||
| const logger = require("./logger.cjs"); | ||
| const copyFilesPlugin = require("./copy-files-plugin.cjs"); | ||
| const babelDeadCodeElimination = require("babel-dead-code-elimination"); | ||
| exports.deadCodeElimination = ast.deadCodeElimination; | ||
| exports.generateFromAst = ast.generateFromAst; | ||
| exports.parseAst = ast.parseAst; | ||
| exports.stripTypeExports = ast.stripTypeExports; | ||
| exports.logDiff = logger.logDiff; | ||
| exports.copyFilesPlugin = copyFilesPlugin.copyFilesPlugin; | ||
| Object.defineProperty(exports, "findReferencedIdentifiers", { | ||
| enumerable: true, | ||
| get: () => babelDeadCodeElimination.findReferencedIdentifiers | ||
| }); | ||
| //# sourceMappingURL=index.cjs.map | ||
| require("./_virtual/_rolldown/runtime.cjs"); | ||
| const require_ast = require("./ast.cjs"); | ||
| const require_logger = require("./logger.cjs"); | ||
| const require_copy_files_plugin = require("./copy-files-plugin.cjs"); | ||
| let babel_dead_code_elimination = require("babel-dead-code-elimination"); | ||
| exports.copyFilesPlugin = require_copy_files_plugin.copyFilesPlugin; | ||
| exports.deadCodeElimination = require_ast.deadCodeElimination; | ||
| exports.findReferencedIdentifiers = babel_dead_code_elimination.findReferencedIdentifiers; | ||
| exports.generateFromAst = require_ast.generateFromAst; | ||
| exports.logDiff = require_logger.logDiff; | ||
| exports.parseAst = require_ast.parseAst; | ||
| exports.stripTypeExports = require_ast.stripTypeExports; |
+47
-52
@@ -1,55 +0,50 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
| const ansis = require("ansis"); | ||
| const diff = require("diff"); | ||
| const require_runtime = require("./_virtual/_rolldown/runtime.cjs"); | ||
| let ansis = require("ansis"); | ||
| ansis = require_runtime.__toESM(ansis); | ||
| let diff = require("diff"); | ||
| //#region src/logger.ts | ||
| function logDiff(oldStr, newStr) { | ||
| const differences = diff.diffWords(oldStr, newStr); | ||
| let output = ""; | ||
| let unchangedLines = ""; | ||
| function processUnchangedLines(lines) { | ||
| const lineArray = lines.split("\n"); | ||
| if (lineArray.length > 4) { | ||
| return [ | ||
| ansis.dim(lineArray[0]), | ||
| ansis.dim(lineArray[1]), | ||
| "", | ||
| ansis.dim.bold(`... (${lineArray.length - 4} lines) ...`), | ||
| "", | ||
| ansis.dim(lineArray[lineArray.length - 2]), | ||
| ansis.dim(lineArray[lineArray.length - 1]) | ||
| ].join("\n"); | ||
| } | ||
| return ansis.dim(lines); | ||
| } | ||
| differences.forEach((part, index) => { | ||
| const nextPart = differences[index + 1]; | ||
| if (part.added) { | ||
| if (unchangedLines) { | ||
| output += processUnchangedLines(unchangedLines); | ||
| unchangedLines = ""; | ||
| } | ||
| output += ansis.green.bold(part.value); | ||
| if (nextPart?.removed) output += " "; | ||
| } else if (part.removed) { | ||
| if (unchangedLines) { | ||
| output += processUnchangedLines(unchangedLines); | ||
| unchangedLines = ""; | ||
| } | ||
| output += ansis.red.bold(part.value); | ||
| if (nextPart?.added) output += " "; | ||
| } else { | ||
| unchangedLines += part.value; | ||
| } | ||
| }); | ||
| if (unchangedLines) { | ||
| output += processUnchangedLines(unchangedLines); | ||
| } | ||
| if (output) { | ||
| console.log("\nDiff:"); | ||
| console.log(output + "\n\n"); | ||
| } else { | ||
| console.log("No changes"); | ||
| } | ||
| const differences = (0, diff.diffWords)(oldStr, newStr); | ||
| let output = ""; | ||
| let unchangedLines = ""; | ||
| function processUnchangedLines(lines) { | ||
| const lineArray = lines.split("\n"); | ||
| if (lineArray.length > 4) return [ | ||
| ansis.default.dim(lineArray[0]), | ||
| ansis.default.dim(lineArray[1]), | ||
| "", | ||
| ansis.default.dim.bold(`... (${lineArray.length - 4} lines) ...`), | ||
| "", | ||
| ansis.default.dim(lineArray[lineArray.length - 2]), | ||
| ansis.default.dim(lineArray[lineArray.length - 1]) | ||
| ].join("\n"); | ||
| return ansis.default.dim(lines); | ||
| } | ||
| differences.forEach((part, index) => { | ||
| const nextPart = differences[index + 1]; | ||
| if (part.added) { | ||
| if (unchangedLines) { | ||
| output += processUnchangedLines(unchangedLines); | ||
| unchangedLines = ""; | ||
| } | ||
| output += ansis.default.green.bold(part.value); | ||
| if (nextPart?.removed) output += " "; | ||
| } else if (part.removed) { | ||
| if (unchangedLines) { | ||
| output += processUnchangedLines(unchangedLines); | ||
| unchangedLines = ""; | ||
| } | ||
| output += ansis.default.red.bold(part.value); | ||
| if (nextPart?.added) output += " "; | ||
| } else unchangedLines += part.value; | ||
| }); | ||
| if (unchangedLines) output += processUnchangedLines(unchangedLines); | ||
| if (output) { | ||
| console.log("\nDiff:"); | ||
| console.log(output + "\n\n"); | ||
| } else console.log("No changes"); | ||
| } | ||
| //#endregion | ||
| exports.logDiff = logDiff; | ||
| //# sourceMappingURL=logger.cjs.map | ||
| //# sourceMappingURL=logger.cjs.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"logger.cjs","sources":["../../src/logger.ts"],"sourcesContent":["import ansis from 'ansis'\nimport { diffWords } from 'diff'\n\nexport function logDiff(oldStr: string, newStr: string) {\n const differences = diffWords(oldStr, newStr)\n\n let output = ''\n let unchangedLines = ''\n\n function processUnchangedLines(lines: string): string {\n const lineArray = lines.split('\\n')\n if (lineArray.length > 4) {\n return [\n ansis.dim(lineArray[0]),\n ansis.dim(lineArray[1]),\n '',\n ansis.dim.bold(`... (${lineArray.length - 4} lines) ...`),\n '',\n ansis.dim(lineArray[lineArray.length - 2]),\n ansis.dim(lineArray[lineArray.length - 1]),\n ].join('\\n')\n }\n return ansis.dim(lines)\n }\n\n differences.forEach((part, index) => {\n const nextPart = differences[index + 1]\n\n if (part.added) {\n if (unchangedLines) {\n output += processUnchangedLines(unchangedLines)\n unchangedLines = ''\n }\n output += ansis.green.bold(part.value)\n if (nextPart?.removed) output += ' '\n } else if (part.removed) {\n if (unchangedLines) {\n output += processUnchangedLines(unchangedLines)\n unchangedLines = ''\n }\n output += ansis.red.bold(part.value)\n if (nextPart?.added) output += ' '\n } else {\n unchangedLines += part.value\n }\n })\n\n // Process any remaining unchanged lines at the end\n if (unchangedLines) {\n output += processUnchangedLines(unchangedLines)\n }\n\n if (output) {\n console.log('\\nDiff:')\n console.log(output + '\\n\\n')\n } else {\n console.log('No changes')\n }\n}\n"],"names":["diffWords"],"mappings":";;;;AAGO,SAAS,QAAQ,QAAgB,QAAgB;AACtD,QAAM,cAAcA,KAAAA,UAAU,QAAQ,MAAM;AAE5C,MAAI,SAAS;AACb,MAAI,iBAAiB;AAErB,WAAS,sBAAsB,OAAuB;AACpD,UAAM,YAAY,MAAM,MAAM,IAAI;AAClC,QAAI,UAAU,SAAS,GAAG;AACxB,aAAO;AAAA,QACL,MAAM,IAAI,UAAU,CAAC,CAAC;AAAA,QACtB,MAAM,IAAI,UAAU,CAAC,CAAC;AAAA,QACtB;AAAA,QACA,MAAM,IAAI,KAAK,QAAQ,UAAU,SAAS,CAAC,aAAa;AAAA,QACxD;AAAA,QACA,MAAM,IAAI,UAAU,UAAU,SAAS,CAAC,CAAC;AAAA,QACzC,MAAM,IAAI,UAAU,UAAU,SAAS,CAAC,CAAC;AAAA,MAAA,EACzC,KAAK,IAAI;AAAA,IACb;AACA,WAAO,MAAM,IAAI,KAAK;AAAA,EACxB;AAEA,cAAY,QAAQ,CAAC,MAAM,UAAU;AACnC,UAAM,WAAW,YAAY,QAAQ,CAAC;AAEtC,QAAI,KAAK,OAAO;AACd,UAAI,gBAAgB;AAClB,kBAAU,sBAAsB,cAAc;AAC9C,yBAAiB;AAAA,MACnB;AACA,gBAAU,MAAM,MAAM,KAAK,KAAK,KAAK;AACrC,UAAI,UAAU,QAAS,WAAU;AAAA,IACnC,WAAW,KAAK,SAAS;AACvB,UAAI,gBAAgB;AAClB,kBAAU,sBAAsB,cAAc;AAC9C,yBAAiB;AAAA,MACnB;AACA,gBAAU,MAAM,IAAI,KAAK,KAAK,KAAK;AACnC,UAAI,UAAU,MAAO,WAAU;AAAA,IACjC,OAAO;AACL,wBAAkB,KAAK;AAAA,IACzB;AAAA,EACF,CAAC;AAGD,MAAI,gBAAgB;AAClB,cAAU,sBAAsB,cAAc;AAAA,EAChD;AAEA,MAAI,QAAQ;AACV,YAAQ,IAAI,SAAS;AACrB,YAAQ,IAAI,SAAS,MAAM;AAAA,EAC7B,OAAO;AACL,YAAQ,IAAI,YAAY;AAAA,EAC1B;AACF;;"} | ||
| {"version":3,"file":"logger.cjs","names":[],"sources":["../../src/logger.ts"],"sourcesContent":["import ansis from 'ansis'\nimport { diffWords } from 'diff'\n\nexport function logDiff(oldStr: string, newStr: string) {\n const differences = diffWords(oldStr, newStr)\n\n let output = ''\n let unchangedLines = ''\n\n function processUnchangedLines(lines: string): string {\n const lineArray = lines.split('\\n')\n if (lineArray.length > 4) {\n return [\n ansis.dim(lineArray[0]),\n ansis.dim(lineArray[1]),\n '',\n ansis.dim.bold(`... (${lineArray.length - 4} lines) ...`),\n '',\n ansis.dim(lineArray[lineArray.length - 2]),\n ansis.dim(lineArray[lineArray.length - 1]),\n ].join('\\n')\n }\n return ansis.dim(lines)\n }\n\n differences.forEach((part, index) => {\n const nextPart = differences[index + 1]\n\n if (part.added) {\n if (unchangedLines) {\n output += processUnchangedLines(unchangedLines)\n unchangedLines = ''\n }\n output += ansis.green.bold(part.value)\n if (nextPart?.removed) output += ' '\n } else if (part.removed) {\n if (unchangedLines) {\n output += processUnchangedLines(unchangedLines)\n unchangedLines = ''\n }\n output += ansis.red.bold(part.value)\n if (nextPart?.added) output += ' '\n } else {\n unchangedLines += part.value\n }\n })\n\n // Process any remaining unchanged lines at the end\n if (unchangedLines) {\n output += processUnchangedLines(unchangedLines)\n }\n\n if (output) {\n console.log('\\nDiff:')\n console.log(output + '\\n\\n')\n } else {\n console.log('No changes')\n }\n}\n"],"mappings":";;;;;AAGA,SAAgB,QAAQ,QAAgB,QAAgB;CACtD,MAAM,eAAA,GAAA,KAAA,WAAwB,QAAQ,OAAO;CAE7C,IAAI,SAAS;CACb,IAAI,iBAAiB;CAErB,SAAS,sBAAsB,OAAuB;EACpD,MAAM,YAAY,MAAM,MAAM,KAAK;AACnC,MAAI,UAAU,SAAS,EACrB,QAAO;GACL,MAAA,QAAM,IAAI,UAAU,GAAG;GACvB,MAAA,QAAM,IAAI,UAAU,GAAG;GACvB;GACA,MAAA,QAAM,IAAI,KAAK,QAAQ,UAAU,SAAS,EAAE,aAAa;GACzD;GACA,MAAA,QAAM,IAAI,UAAU,UAAU,SAAS,GAAG;GAC1C,MAAA,QAAM,IAAI,UAAU,UAAU,SAAS,GAAG;GAC3C,CAAC,KAAK,KAAK;AAEd,SAAO,MAAA,QAAM,IAAI,MAAM;;AAGzB,aAAY,SAAS,MAAM,UAAU;EACnC,MAAM,WAAW,YAAY,QAAQ;AAErC,MAAI,KAAK,OAAO;AACd,OAAI,gBAAgB;AAClB,cAAU,sBAAsB,eAAe;AAC/C,qBAAiB;;AAEnB,aAAU,MAAA,QAAM,MAAM,KAAK,KAAK,MAAM;AACtC,OAAI,UAAU,QAAS,WAAU;aACxB,KAAK,SAAS;AACvB,OAAI,gBAAgB;AAClB,cAAU,sBAAsB,eAAe;AAC/C,qBAAiB;;AAEnB,aAAU,MAAA,QAAM,IAAI,KAAK,KAAK,MAAM;AACpC,OAAI,UAAU,MAAO,WAAU;QAE/B,mBAAkB,KAAK;GAEzB;AAGF,KAAI,eACF,WAAU,sBAAsB,eAAe;AAGjD,KAAI,QAAQ;AACV,UAAQ,IAAI,UAAU;AACtB,UAAQ,IAAI,SAAS,OAAO;OAE5B,SAAQ,IAAI,aAAa"} |
+87
-66
| import { parse } from "@babel/parser"; | ||
| import _generate from "@babel/generator"; | ||
| import * as t from "@babel/types"; | ||
| import { deadCodeElimination as deadCodeElimination$1 } from "babel-dead-code-elimination"; | ||
| import { findReferencedIdentifiers } from "babel-dead-code-elimination"; | ||
| import { deadCodeElimination, findReferencedIdentifiers } from "babel-dead-code-elimination"; | ||
| //#region src/ast.ts | ||
| function parseAst({ code, ...opts }) { | ||
| return parse(code, { | ||
| plugins: ["jsx", "typescript", "explicitResourceManagement"], | ||
| sourceType: "module", | ||
| ...opts | ||
| }); | ||
| return parse(code, { | ||
| plugins: [ | ||
| "jsx", | ||
| "typescript", | ||
| "explicitResourceManagement" | ||
| ], | ||
| sourceType: "module", | ||
| ...opts | ||
| }); | ||
| } | ||
| let generate = _generate; | ||
| if ("default" in generate) { | ||
| generate = generate.default; | ||
| } | ||
| var generate = _generate; | ||
| if ("default" in generate) generate = generate.default; | ||
| function generateFromAst(ast, opts) { | ||
| return generate( | ||
| ast, | ||
| opts ? { importAttributesKeyword: "with", sourceMaps: true, ...opts } : void 0 | ||
| ); | ||
| return generate(ast, opts ? { | ||
| importAttributesKeyword: "with", | ||
| sourceMaps: true, | ||
| ...opts | ||
| } : void 0); | ||
| } | ||
| /** | ||
| * Strips TypeScript type-only exports and imports from an AST. | ||
| * | ||
| * This is necessary because babel-dead-code-elimination doesn't handle | ||
| * TypeScript type exports/imports. When a type export references an import | ||
| * that pulls in server-only code, the dead code elimination won't remove | ||
| * that import because it sees the type as still referencing it. | ||
| * | ||
| * This function removes: | ||
| * - `export type Foo = ...` | ||
| * - `export interface Foo { ... }` | ||
| * - `export type { Foo } from './module'` | ||
| * - `export type * from './module'` | ||
| * - Type specifiers in mixed exports: `export { value, type Foo }` -> `export { value }` | ||
| * - `import type { Foo } from './module'` | ||
| * - Type specifiers in mixed imports: `import { value, type Foo } from './module'` -> `import { value }` | ||
| * | ||
| * Note: Non-exported type/interface declarations are preserved as they may be | ||
| * used as type annotations within the code. | ||
| * | ||
| * @param ast - The Babel AST (or ParseResult) to mutate | ||
| */ | ||
| function stripTypeExports(ast) { | ||
| ast.program.body = ast.program.body.filter((node) => { | ||
| if (t.isExportNamedDeclaration(node)) { | ||
| if (node.exportKind === "type") { | ||
| return false; | ||
| } | ||
| if (node.specifiers.length > 0) { | ||
| node.specifiers = node.specifiers.filter((specifier) => { | ||
| if (t.isExportSpecifier(specifier)) { | ||
| return specifier.exportKind !== "type"; | ||
| } | ||
| return true; | ||
| }); | ||
| if (node.specifiers.length === 0 && !node.declaration) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| if (t.isExportAllDeclaration(node)) { | ||
| if (node.exportKind === "type") { | ||
| return false; | ||
| } | ||
| } | ||
| if (t.isImportDeclaration(node)) { | ||
| if (node.importKind === "type") { | ||
| return false; | ||
| } | ||
| if (node.specifiers.length > 0) { | ||
| node.specifiers = node.specifiers.filter((specifier) => { | ||
| if (t.isImportSpecifier(specifier)) { | ||
| return specifier.importKind !== "type"; | ||
| } | ||
| return true; | ||
| }); | ||
| if (node.specifiers.length === 0) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| return true; | ||
| }); | ||
| ast.program.body = ast.program.body.filter((node) => { | ||
| if (t.isExportNamedDeclaration(node)) { | ||
| if (node.exportKind === "type") return false; | ||
| if (node.specifiers.length > 0) { | ||
| node.specifiers = node.specifiers.filter((specifier) => { | ||
| if (t.isExportSpecifier(specifier)) return specifier.exportKind !== "type"; | ||
| return true; | ||
| }); | ||
| if (node.specifiers.length === 0 && !node.declaration) return false; | ||
| } | ||
| } | ||
| if (t.isExportAllDeclaration(node)) { | ||
| if (node.exportKind === "type") return false; | ||
| } | ||
| if (t.isImportDeclaration(node)) { | ||
| if (node.importKind === "type") return false; | ||
| if (node.specifiers.length > 0) { | ||
| node.specifiers = node.specifiers.filter((specifier) => { | ||
| if (t.isImportSpecifier(specifier)) return specifier.importKind !== "type"; | ||
| return true; | ||
| }); | ||
| if (node.specifiers.length === 0) return false; | ||
| } | ||
| } | ||
| return true; | ||
| }); | ||
| } | ||
| function deadCodeElimination(ast, candidates) { | ||
| stripTypeExports(ast); | ||
| deadCodeElimination$1(ast, candidates); | ||
| /** | ||
| * Performs dead code elimination on the AST, with TypeScript type stripping. | ||
| * | ||
| * This is a wrapper around babel-dead-code-elimination that first strips | ||
| * TypeScript type-only exports and imports. This is necessary because | ||
| * babel-dead-code-elimination doesn't handle type exports, which can cause | ||
| * imports to be retained when they're only referenced by type exports. | ||
| * | ||
| * @param ast - The Babel AST to mutate | ||
| * @param candidates - Optional set of identifier paths to consider for removal. | ||
| * If provided, only these identifiers will be candidates for removal. | ||
| * This should be the result of `findReferencedIdentifiers(ast)` called | ||
| * before any AST transformations. | ||
| */ | ||
| function deadCodeElimination$1(ast, candidates) { | ||
| stripTypeExports(ast); | ||
| deadCodeElimination(ast, candidates); | ||
| } | ||
| export { | ||
| deadCodeElimination, | ||
| findReferencedIdentifiers, | ||
| generateFromAst, | ||
| parseAst, | ||
| stripTypeExports | ||
| }; | ||
| //# sourceMappingURL=ast.js.map | ||
| //#endregion | ||
| export { deadCodeElimination$1 as deadCodeElimination, findReferencedIdentifiers, generateFromAst, parseAst, stripTypeExports }; | ||
| //# sourceMappingURL=ast.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"ast.js","sources":["../../src/ast.ts"],"sourcesContent":["import { parse } from '@babel/parser'\nimport _generate from '@babel/generator'\nimport * as t from '@babel/types'\nimport {\n deadCodeElimination as _deadCodeElimination,\n findReferencedIdentifiers,\n} from 'babel-dead-code-elimination'\nimport type { GeneratorOptions, GeneratorResult } from '@babel/generator'\nimport type { ParseResult, ParserOptions } from '@babel/parser'\nimport type * as _babel_types from '@babel/types'\n\nexport type ParseAstOptions = ParserOptions & {\n code: string\n}\n\nexport type ParseAstResult = ParseResult<_babel_types.File>\nexport function parseAst({ code, ...opts }: ParseAstOptions): ParseAstResult {\n return parse(code, {\n plugins: ['jsx', 'typescript', 'explicitResourceManagement'],\n sourceType: 'module',\n ...opts,\n })\n}\n\nlet generate = _generate\n\nif ('default' in generate) {\n generate = generate.default as typeof generate\n}\ntype GenerateFromAstOptions = GeneratorOptions &\n Required<Pick<GeneratorOptions, 'sourceFileName' | 'filename'>>\nexport function generateFromAst(\n ast: _babel_types.Node,\n opts?: GenerateFromAstOptions,\n): GeneratorResult {\n return generate(\n ast,\n opts\n ? { importAttributesKeyword: 'with', sourceMaps: true, ...opts }\n : undefined,\n )\n}\nexport type { GeneratorResult } from '@babel/generator'\n\n/**\n * Strips TypeScript type-only exports and imports from an AST.\n *\n * This is necessary because babel-dead-code-elimination doesn't handle\n * TypeScript type exports/imports. When a type export references an import\n * that pulls in server-only code, the dead code elimination won't remove\n * that import because it sees the type as still referencing it.\n *\n * This function removes:\n * - `export type Foo = ...`\n * - `export interface Foo { ... }`\n * - `export type { Foo } from './module'`\n * - `export type * from './module'`\n * - Type specifiers in mixed exports: `export { value, type Foo }` -> `export { value }`\n * - `import type { Foo } from './module'`\n * - Type specifiers in mixed imports: `import { value, type Foo } from './module'` -> `import { value }`\n *\n * Note: Non-exported type/interface declarations are preserved as they may be\n * used as type annotations within the code.\n *\n * @param ast - The Babel AST (or ParseResult) to mutate\n */\nexport function stripTypeExports(ast: ParseResult<_babel_types.File>): void {\n // Filter the program body to remove type-only nodes\n ast.program.body = ast.program.body.filter((node) => {\n // Handle export declarations\n if (t.isExportNamedDeclaration(node)) {\n // Remove entire export if it's a type-only export\n // e.g., `export type Foo = string`, `export interface Bar {}`, `export type { X } from './y'`\n if (node.exportKind === 'type') {\n return false\n }\n\n // For value exports with mixed specifiers, filter out type-only specifiers\n // e.g., `export { value, type TypeOnly }` -> `export { value }`\n if (node.specifiers.length > 0) {\n node.specifiers = node.specifiers.filter((specifier) => {\n if (t.isExportSpecifier(specifier)) {\n return specifier.exportKind !== 'type'\n }\n return true\n })\n\n // If all specifiers were removed, remove the entire export declaration\n // (unless it has a declaration like `export const x = 1`)\n if (node.specifiers.length === 0 && !node.declaration) {\n return false\n }\n }\n }\n\n // Handle type-only export-all declarations\n // e.g., `export type * from './module'`\n if (t.isExportAllDeclaration(node)) {\n if (node.exportKind === 'type') {\n return false\n }\n }\n\n // Handle import declarations\n if (t.isImportDeclaration(node)) {\n // Remove entire import if it's a type-only import\n // e.g., `import type { Foo } from './module'`\n if (node.importKind === 'type') {\n return false\n }\n\n // For value imports with mixed specifiers, filter out type-only specifiers\n // e.g., `import { value, type TypeOnly } from './module'` -> `import { value }`\n if (node.specifiers.length > 0) {\n node.specifiers = node.specifiers.filter((specifier) => {\n if (t.isImportSpecifier(specifier)) {\n return specifier.importKind !== 'type'\n }\n return true\n })\n\n // If all specifiers were removed, remove the entire import declaration\n if (node.specifiers.length === 0) {\n return false\n }\n }\n }\n\n return true\n })\n}\n\n// Re-export findReferencedIdentifiers from babel-dead-code-elimination\nexport { findReferencedIdentifiers }\n\n/**\n * Performs dead code elimination on the AST, with TypeScript type stripping.\n *\n * This is a wrapper around babel-dead-code-elimination that first strips\n * TypeScript type-only exports and imports. This is necessary because\n * babel-dead-code-elimination doesn't handle type exports, which can cause\n * imports to be retained when they're only referenced by type exports.\n *\n * @param ast - The Babel AST to mutate\n * @param candidates - Optional set of identifier paths to consider for removal.\n * If provided, only these identifiers will be candidates for removal.\n * This should be the result of `findReferencedIdentifiers(ast)` called\n * before any AST transformations.\n */\nexport function deadCodeElimination(\n ast: ParseResult<_babel_types.File>,\n candidates?: ReturnType<typeof findReferencedIdentifiers>,\n): void {\n // First strip TypeScript type-only exports and imports\n stripTypeExports(ast)\n\n // Then run the original dead code elimination\n _deadCodeElimination(ast, candidates)\n}\n"],"names":["_deadCodeElimination"],"mappings":";;;;;AAgBO,SAAS,SAAS,EAAE,MAAM,GAAG,QAAyC;AAC3E,SAAO,MAAM,MAAM;AAAA,IACjB,SAAS,CAAC,OAAO,cAAc,4BAA4B;AAAA,IAC3D,YAAY;AAAA,IACZ,GAAG;AAAA,EAAA,CACJ;AACH;AAEA,IAAI,WAAW;AAEf,IAAI,aAAa,UAAU;AACzB,aAAW,SAAS;AACtB;AAGO,SAAS,gBACd,KACA,MACiB;AACjB,SAAO;AAAA,IACL;AAAA,IACA,OACI,EAAE,yBAAyB,QAAQ,YAAY,MAAM,GAAG,SACxD;AAAA,EAAA;AAER;AAyBO,SAAS,iBAAiB,KAA2C;AAE1E,MAAI,QAAQ,OAAO,IAAI,QAAQ,KAAK,OAAO,CAAC,SAAS;AAEnD,QAAI,EAAE,yBAAyB,IAAI,GAAG;AAGpC,UAAI,KAAK,eAAe,QAAQ;AAC9B,eAAO;AAAA,MACT;AAIA,UAAI,KAAK,WAAW,SAAS,GAAG;AAC9B,aAAK,aAAa,KAAK,WAAW,OAAO,CAAC,cAAc;AACtD,cAAI,EAAE,kBAAkB,SAAS,GAAG;AAClC,mBAAO,UAAU,eAAe;AAAA,UAClC;AACA,iBAAO;AAAA,QACT,CAAC;AAID,YAAI,KAAK,WAAW,WAAW,KAAK,CAAC,KAAK,aAAa;AACrD,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAIA,QAAI,EAAE,uBAAuB,IAAI,GAAG;AAClC,UAAI,KAAK,eAAe,QAAQ;AAC9B,eAAO;AAAA,MACT;AAAA,IACF;AAGA,QAAI,EAAE,oBAAoB,IAAI,GAAG;AAG/B,UAAI,KAAK,eAAe,QAAQ;AAC9B,eAAO;AAAA,MACT;AAIA,UAAI,KAAK,WAAW,SAAS,GAAG;AAC9B,aAAK,aAAa,KAAK,WAAW,OAAO,CAAC,cAAc;AACtD,cAAI,EAAE,kBAAkB,SAAS,GAAG;AAClC,mBAAO,UAAU,eAAe;AAAA,UAClC;AACA,iBAAO;AAAA,QACT,CAAC;AAGD,YAAI,KAAK,WAAW,WAAW,GAAG;AAChC,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT,CAAC;AACH;AAmBO,SAAS,oBACd,KACA,YACM;AAEN,mBAAiB,GAAG;AAGpBA,wBAAqB,KAAK,UAAU;AACtC;"} | ||
| {"version":3,"file":"ast.js","names":[],"sources":["../../src/ast.ts"],"sourcesContent":["import { parse } from '@babel/parser'\nimport _generate from '@babel/generator'\nimport * as t from '@babel/types'\nimport {\n deadCodeElimination as _deadCodeElimination,\n findReferencedIdentifiers,\n} from 'babel-dead-code-elimination'\nimport type { GeneratorOptions, GeneratorResult } from '@babel/generator'\nimport type { ParseResult, ParserOptions } from '@babel/parser'\nimport type * as _babel_types from '@babel/types'\n\nexport type ParseAstOptions = ParserOptions & {\n code: string\n}\n\nexport type ParseAstResult = ParseResult<_babel_types.File>\nexport function parseAst({ code, ...opts }: ParseAstOptions): ParseAstResult {\n return parse(code, {\n plugins: ['jsx', 'typescript', 'explicitResourceManagement'],\n sourceType: 'module',\n ...opts,\n })\n}\n\nlet generate = _generate\n\nif ('default' in generate) {\n generate = generate.default as typeof generate\n}\ntype GenerateFromAstOptions = GeneratorOptions &\n Required<Pick<GeneratorOptions, 'sourceFileName' | 'filename'>>\nexport function generateFromAst(\n ast: _babel_types.Node,\n opts?: GenerateFromAstOptions,\n): GeneratorResult {\n return generate(\n ast,\n opts\n ? { importAttributesKeyword: 'with', sourceMaps: true, ...opts }\n : undefined,\n )\n}\nexport type { GeneratorResult } from '@babel/generator'\n\n/**\n * Strips TypeScript type-only exports and imports from an AST.\n *\n * This is necessary because babel-dead-code-elimination doesn't handle\n * TypeScript type exports/imports. When a type export references an import\n * that pulls in server-only code, the dead code elimination won't remove\n * that import because it sees the type as still referencing it.\n *\n * This function removes:\n * - `export type Foo = ...`\n * - `export interface Foo { ... }`\n * - `export type { Foo } from './module'`\n * - `export type * from './module'`\n * - Type specifiers in mixed exports: `export { value, type Foo }` -> `export { value }`\n * - `import type { Foo } from './module'`\n * - Type specifiers in mixed imports: `import { value, type Foo } from './module'` -> `import { value }`\n *\n * Note: Non-exported type/interface declarations are preserved as they may be\n * used as type annotations within the code.\n *\n * @param ast - The Babel AST (or ParseResult) to mutate\n */\nexport function stripTypeExports(ast: ParseResult<_babel_types.File>): void {\n // Filter the program body to remove type-only nodes\n ast.program.body = ast.program.body.filter((node) => {\n // Handle export declarations\n if (t.isExportNamedDeclaration(node)) {\n // Remove entire export if it's a type-only export\n // e.g., `export type Foo = string`, `export interface Bar {}`, `export type { X } from './y'`\n if (node.exportKind === 'type') {\n return false\n }\n\n // For value exports with mixed specifiers, filter out type-only specifiers\n // e.g., `export { value, type TypeOnly }` -> `export { value }`\n if (node.specifiers.length > 0) {\n node.specifiers = node.specifiers.filter((specifier) => {\n if (t.isExportSpecifier(specifier)) {\n return specifier.exportKind !== 'type'\n }\n return true\n })\n\n // If all specifiers were removed, remove the entire export declaration\n // (unless it has a declaration like `export const x = 1`)\n if (node.specifiers.length === 0 && !node.declaration) {\n return false\n }\n }\n }\n\n // Handle type-only export-all declarations\n // e.g., `export type * from './module'`\n if (t.isExportAllDeclaration(node)) {\n if (node.exportKind === 'type') {\n return false\n }\n }\n\n // Handle import declarations\n if (t.isImportDeclaration(node)) {\n // Remove entire import if it's a type-only import\n // e.g., `import type { Foo } from './module'`\n if (node.importKind === 'type') {\n return false\n }\n\n // For value imports with mixed specifiers, filter out type-only specifiers\n // e.g., `import { value, type TypeOnly } from './module'` -> `import { value }`\n if (node.specifiers.length > 0) {\n node.specifiers = node.specifiers.filter((specifier) => {\n if (t.isImportSpecifier(specifier)) {\n return specifier.importKind !== 'type'\n }\n return true\n })\n\n // If all specifiers were removed, remove the entire import declaration\n if (node.specifiers.length === 0) {\n return false\n }\n }\n }\n\n return true\n })\n}\n\n// Re-export findReferencedIdentifiers from babel-dead-code-elimination\nexport { findReferencedIdentifiers }\n\n/**\n * Performs dead code elimination on the AST, with TypeScript type stripping.\n *\n * This is a wrapper around babel-dead-code-elimination that first strips\n * TypeScript type-only exports and imports. This is necessary because\n * babel-dead-code-elimination doesn't handle type exports, which can cause\n * imports to be retained when they're only referenced by type exports.\n *\n * @param ast - The Babel AST to mutate\n * @param candidates - Optional set of identifier paths to consider for removal.\n * If provided, only these identifiers will be candidates for removal.\n * This should be the result of `findReferencedIdentifiers(ast)` called\n * before any AST transformations.\n */\nexport function deadCodeElimination(\n ast: ParseResult<_babel_types.File>,\n candidates?: ReturnType<typeof findReferencedIdentifiers>,\n): void {\n // First strip TypeScript type-only exports and imports\n stripTypeExports(ast)\n\n // Then run the original dead code elimination\n _deadCodeElimination(ast, candidates)\n}\n"],"mappings":";;;;;AAgBA,SAAgB,SAAS,EAAE,MAAM,GAAG,QAAyC;AAC3E,QAAO,MAAM,MAAM;EACjB,SAAS;GAAC;GAAO;GAAc;GAA6B;EAC5D,YAAY;EACZ,GAAG;EACJ,CAAC;;AAGJ,IAAI,WAAW;AAEf,IAAI,aAAa,SACf,YAAW,SAAS;AAItB,SAAgB,gBACd,KACA,MACiB;AACjB,QAAO,SACL,KACA,OACI;EAAE,yBAAyB;EAAQ,YAAY;EAAM,GAAG;EAAM,GAC9D,KAAA,EACL;;;;;;;;;;;;;;;;;;;;;;;;AA0BH,SAAgB,iBAAiB,KAA2C;AAE1E,KAAI,QAAQ,OAAO,IAAI,QAAQ,KAAK,QAAQ,SAAS;AAEnD,MAAI,EAAE,yBAAyB,KAAK,EAAE;AAGpC,OAAI,KAAK,eAAe,OACtB,QAAO;AAKT,OAAI,KAAK,WAAW,SAAS,GAAG;AAC9B,SAAK,aAAa,KAAK,WAAW,QAAQ,cAAc;AACtD,SAAI,EAAE,kBAAkB,UAAU,CAChC,QAAO,UAAU,eAAe;AAElC,YAAO;MACP;AAIF,QAAI,KAAK,WAAW,WAAW,KAAK,CAAC,KAAK,YACxC,QAAO;;;AAOb,MAAI,EAAE,uBAAuB,KAAK;OAC5B,KAAK,eAAe,OACtB,QAAO;;AAKX,MAAI,EAAE,oBAAoB,KAAK,EAAE;AAG/B,OAAI,KAAK,eAAe,OACtB,QAAO;AAKT,OAAI,KAAK,WAAW,SAAS,GAAG;AAC9B,SAAK,aAAa,KAAK,WAAW,QAAQ,cAAc;AACtD,SAAI,EAAE,kBAAkB,UAAU,CAChC,QAAO,UAAU,eAAe;AAElC,YAAO;MACP;AAGF,QAAI,KAAK,WAAW,WAAW,EAC7B,QAAO;;;AAKb,SAAO;GACP;;;;;;;;;;;;;;;;AAoBJ,SAAgB,sBACd,KACA,YACM;AAEN,kBAAiB,IAAI;AAGrB,qBAAqB,KAAK,WAAW"} |
@@ -1,30 +0,23 @@ | ||
| import { mkdir, copyFile } from "node:fs/promises"; | ||
| import { join, dirname } from "pathe"; | ||
| import { copyFile, mkdir } from "node:fs/promises"; | ||
| import { dirname, join } from "pathe"; | ||
| import { glob } from "tinyglobby"; | ||
| function copyFilesPlugin({ | ||
| fromDir, | ||
| toDir, | ||
| pattern = "**" | ||
| }) { | ||
| return { | ||
| name: "copy-files", | ||
| async writeBundle() { | ||
| const entries = await glob(pattern, { cwd: fromDir }); | ||
| if (entries.length === 0) { | ||
| throw new Error( | ||
| `No files found matching pattern "${pattern}" in directory "${fromDir}"` | ||
| ); | ||
| } | ||
| for (const entry of entries) { | ||
| const srcPath = join(fromDir, entry); | ||
| const destPath = join(toDir, entry); | ||
| await mkdir(dirname(destPath), { recursive: true }); | ||
| await copyFile(srcPath, destPath); | ||
| } | ||
| } | ||
| }; | ||
| //#region src/copy-files-plugin.ts | ||
| function copyFilesPlugin({ fromDir, toDir, pattern = "**" }) { | ||
| return { | ||
| name: "copy-files", | ||
| async writeBundle() { | ||
| const entries = await glob(pattern, { cwd: fromDir }); | ||
| if (entries.length === 0) throw new Error(`No files found matching pattern "${pattern}" in directory "${fromDir}"`); | ||
| for (const entry of entries) { | ||
| const srcPath = join(fromDir, entry); | ||
| const destPath = join(toDir, entry); | ||
| await mkdir(dirname(destPath), { recursive: true }); | ||
| await copyFile(srcPath, destPath); | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| export { | ||
| copyFilesPlugin | ||
| }; | ||
| //# sourceMappingURL=copy-files-plugin.js.map | ||
| //#endregion | ||
| export { copyFilesPlugin }; | ||
| //# sourceMappingURL=copy-files-plugin.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"copy-files-plugin.js","sources":["../../src/copy-files-plugin.ts"],"sourcesContent":["import { copyFile, mkdir } from 'node:fs/promises'\nimport { dirname, join } from 'pathe'\nimport { glob } from 'tinyglobby'\nimport type { Plugin } from 'vite'\n\nexport function copyFilesPlugin({\n fromDir,\n toDir,\n pattern = '**',\n}: {\n pattern?: string | Array<string>\n fromDir: string\n toDir: string\n}): Plugin {\n return {\n name: 'copy-files',\n async writeBundle() {\n const entries = await glob(pattern, { cwd: fromDir })\n if (entries.length === 0) {\n throw new Error(\n `No files found matching pattern \"${pattern}\" in directory \"${fromDir}\"`,\n )\n }\n\n for (const entry of entries) {\n const srcPath = join(fromDir, entry)\n const destPath = join(toDir, entry)\n // Ensure the destination directory exists\n await mkdir(dirname(destPath), { recursive: true })\n await copyFile(srcPath, destPath)\n }\n },\n }\n}\n"],"names":[],"mappings":";;;AAKO,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA,UAAU;AACZ,GAIW;AACT,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,cAAc;AAClB,YAAM,UAAU,MAAM,KAAK,SAAS,EAAE,KAAK,SAAS;AACpD,UAAI,QAAQ,WAAW,GAAG;AACxB,cAAM,IAAI;AAAA,UACR,oCAAoC,OAAO,mBAAmB,OAAO;AAAA,QAAA;AAAA,MAEzE;AAEA,iBAAW,SAAS,SAAS;AAC3B,cAAM,UAAU,KAAK,SAAS,KAAK;AACnC,cAAM,WAAW,KAAK,OAAO,KAAK;AAElC,cAAM,MAAM,QAAQ,QAAQ,GAAG,EAAE,WAAW,MAAM;AAClD,cAAM,SAAS,SAAS,QAAQ;AAAA,MAClC;AAAA,IACF;AAAA,EAAA;AAEJ;"} | ||
| {"version":3,"file":"copy-files-plugin.js","names":[],"sources":["../../src/copy-files-plugin.ts"],"sourcesContent":["import { copyFile, mkdir } from 'node:fs/promises'\nimport { dirname, join } from 'pathe'\nimport { glob } from 'tinyglobby'\nimport type { Plugin } from 'vite'\n\nexport function copyFilesPlugin({\n fromDir,\n toDir,\n pattern = '**',\n}: {\n pattern?: string | Array<string>\n fromDir: string\n toDir: string\n}): Plugin {\n return {\n name: 'copy-files',\n async writeBundle() {\n const entries = await glob(pattern, { cwd: fromDir })\n if (entries.length === 0) {\n throw new Error(\n `No files found matching pattern \"${pattern}\" in directory \"${fromDir}\"`,\n )\n }\n\n for (const entry of entries) {\n const srcPath = join(fromDir, entry)\n const destPath = join(toDir, entry)\n // Ensure the destination directory exists\n await mkdir(dirname(destPath), { recursive: true })\n await copyFile(srcPath, destPath)\n }\n },\n }\n}\n"],"mappings":";;;;AAKA,SAAgB,gBAAgB,EAC9B,SACA,OACA,UAAU,QAKD;AACT,QAAO;EACL,MAAM;EACN,MAAM,cAAc;GAClB,MAAM,UAAU,MAAM,KAAK,SAAS,EAAE,KAAK,SAAS,CAAC;AACrD,OAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MACR,oCAAoC,QAAQ,kBAAkB,QAAQ,GACvE;AAGH,QAAK,MAAM,SAAS,SAAS;IAC3B,MAAM,UAAU,KAAK,SAAS,MAAM;IACpC,MAAM,WAAW,KAAK,OAAO,MAAM;AAEnC,UAAM,MAAM,QAAQ,SAAS,EAAE,EAAE,WAAW,MAAM,CAAC;AACnD,UAAM,SAAS,SAAS,SAAS;;;EAGtC"} |
+2
-12
@@ -1,14 +0,4 @@ | ||
| import { deadCodeElimination, generateFromAst, parseAst, stripTypeExports } from "./ast.js"; | ||
| import { deadCodeElimination, findReferencedIdentifiers, generateFromAst, parseAst, stripTypeExports } from "./ast.js"; | ||
| import { logDiff } from "./logger.js"; | ||
| import { copyFilesPlugin } from "./copy-files-plugin.js"; | ||
| import { findReferencedIdentifiers } from "babel-dead-code-elimination"; | ||
| export { | ||
| copyFilesPlugin, | ||
| deadCodeElimination, | ||
| findReferencedIdentifiers, | ||
| generateFromAst, | ||
| logDiff, | ||
| parseAst, | ||
| stripTypeExports | ||
| }; | ||
| //# sourceMappingURL=index.js.map | ||
| export { copyFilesPlugin, deadCodeElimination, findReferencedIdentifiers, generateFromAst, logDiff, parseAst, stripTypeExports }; |
+44
-51
| import ansis from "ansis"; | ||
| import { diffWords } from "diff"; | ||
| //#region src/logger.ts | ||
| function logDiff(oldStr, newStr) { | ||
| const differences = diffWords(oldStr, newStr); | ||
| let output = ""; | ||
| let unchangedLines = ""; | ||
| function processUnchangedLines(lines) { | ||
| const lineArray = lines.split("\n"); | ||
| if (lineArray.length > 4) { | ||
| return [ | ||
| ansis.dim(lineArray[0]), | ||
| ansis.dim(lineArray[1]), | ||
| "", | ||
| ansis.dim.bold(`... (${lineArray.length - 4} lines) ...`), | ||
| "", | ||
| ansis.dim(lineArray[lineArray.length - 2]), | ||
| ansis.dim(lineArray[lineArray.length - 1]) | ||
| ].join("\n"); | ||
| } | ||
| return ansis.dim(lines); | ||
| } | ||
| differences.forEach((part, index) => { | ||
| const nextPart = differences[index + 1]; | ||
| if (part.added) { | ||
| if (unchangedLines) { | ||
| output += processUnchangedLines(unchangedLines); | ||
| unchangedLines = ""; | ||
| } | ||
| output += ansis.green.bold(part.value); | ||
| if (nextPart?.removed) output += " "; | ||
| } else if (part.removed) { | ||
| if (unchangedLines) { | ||
| output += processUnchangedLines(unchangedLines); | ||
| unchangedLines = ""; | ||
| } | ||
| output += ansis.red.bold(part.value); | ||
| if (nextPart?.added) output += " "; | ||
| } else { | ||
| unchangedLines += part.value; | ||
| } | ||
| }); | ||
| if (unchangedLines) { | ||
| output += processUnchangedLines(unchangedLines); | ||
| } | ||
| if (output) { | ||
| console.log("\nDiff:"); | ||
| console.log(output + "\n\n"); | ||
| } else { | ||
| console.log("No changes"); | ||
| } | ||
| const differences = diffWords(oldStr, newStr); | ||
| let output = ""; | ||
| let unchangedLines = ""; | ||
| function processUnchangedLines(lines) { | ||
| const lineArray = lines.split("\n"); | ||
| if (lineArray.length > 4) return [ | ||
| ansis.dim(lineArray[0]), | ||
| ansis.dim(lineArray[1]), | ||
| "", | ||
| ansis.dim.bold(`... (${lineArray.length - 4} lines) ...`), | ||
| "", | ||
| ansis.dim(lineArray[lineArray.length - 2]), | ||
| ansis.dim(lineArray[lineArray.length - 1]) | ||
| ].join("\n"); | ||
| return ansis.dim(lines); | ||
| } | ||
| differences.forEach((part, index) => { | ||
| const nextPart = differences[index + 1]; | ||
| if (part.added) { | ||
| if (unchangedLines) { | ||
| output += processUnchangedLines(unchangedLines); | ||
| unchangedLines = ""; | ||
| } | ||
| output += ansis.green.bold(part.value); | ||
| if (nextPart?.removed) output += " "; | ||
| } else if (part.removed) { | ||
| if (unchangedLines) { | ||
| output += processUnchangedLines(unchangedLines); | ||
| unchangedLines = ""; | ||
| } | ||
| output += ansis.red.bold(part.value); | ||
| if (nextPart?.added) output += " "; | ||
| } else unchangedLines += part.value; | ||
| }); | ||
| if (unchangedLines) output += processUnchangedLines(unchangedLines); | ||
| if (output) { | ||
| console.log("\nDiff:"); | ||
| console.log(output + "\n\n"); | ||
| } else console.log("No changes"); | ||
| } | ||
| export { | ||
| logDiff | ||
| }; | ||
| //# sourceMappingURL=logger.js.map | ||
| //#endregion | ||
| export { logDiff }; | ||
| //# sourceMappingURL=logger.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"logger.js","sources":["../../src/logger.ts"],"sourcesContent":["import ansis from 'ansis'\nimport { diffWords } from 'diff'\n\nexport function logDiff(oldStr: string, newStr: string) {\n const differences = diffWords(oldStr, newStr)\n\n let output = ''\n let unchangedLines = ''\n\n function processUnchangedLines(lines: string): string {\n const lineArray = lines.split('\\n')\n if (lineArray.length > 4) {\n return [\n ansis.dim(lineArray[0]),\n ansis.dim(lineArray[1]),\n '',\n ansis.dim.bold(`... (${lineArray.length - 4} lines) ...`),\n '',\n ansis.dim(lineArray[lineArray.length - 2]),\n ansis.dim(lineArray[lineArray.length - 1]),\n ].join('\\n')\n }\n return ansis.dim(lines)\n }\n\n differences.forEach((part, index) => {\n const nextPart = differences[index + 1]\n\n if (part.added) {\n if (unchangedLines) {\n output += processUnchangedLines(unchangedLines)\n unchangedLines = ''\n }\n output += ansis.green.bold(part.value)\n if (nextPart?.removed) output += ' '\n } else if (part.removed) {\n if (unchangedLines) {\n output += processUnchangedLines(unchangedLines)\n unchangedLines = ''\n }\n output += ansis.red.bold(part.value)\n if (nextPart?.added) output += ' '\n } else {\n unchangedLines += part.value\n }\n })\n\n // Process any remaining unchanged lines at the end\n if (unchangedLines) {\n output += processUnchangedLines(unchangedLines)\n }\n\n if (output) {\n console.log('\\nDiff:')\n console.log(output + '\\n\\n')\n } else {\n console.log('No changes')\n }\n}\n"],"names":[],"mappings":";;AAGO,SAAS,QAAQ,QAAgB,QAAgB;AACtD,QAAM,cAAc,UAAU,QAAQ,MAAM;AAE5C,MAAI,SAAS;AACb,MAAI,iBAAiB;AAErB,WAAS,sBAAsB,OAAuB;AACpD,UAAM,YAAY,MAAM,MAAM,IAAI;AAClC,QAAI,UAAU,SAAS,GAAG;AACxB,aAAO;AAAA,QACL,MAAM,IAAI,UAAU,CAAC,CAAC;AAAA,QACtB,MAAM,IAAI,UAAU,CAAC,CAAC;AAAA,QACtB;AAAA,QACA,MAAM,IAAI,KAAK,QAAQ,UAAU,SAAS,CAAC,aAAa;AAAA,QACxD;AAAA,QACA,MAAM,IAAI,UAAU,UAAU,SAAS,CAAC,CAAC;AAAA,QACzC,MAAM,IAAI,UAAU,UAAU,SAAS,CAAC,CAAC;AAAA,MAAA,EACzC,KAAK,IAAI;AAAA,IACb;AACA,WAAO,MAAM,IAAI,KAAK;AAAA,EACxB;AAEA,cAAY,QAAQ,CAAC,MAAM,UAAU;AACnC,UAAM,WAAW,YAAY,QAAQ,CAAC;AAEtC,QAAI,KAAK,OAAO;AACd,UAAI,gBAAgB;AAClB,kBAAU,sBAAsB,cAAc;AAC9C,yBAAiB;AAAA,MACnB;AACA,gBAAU,MAAM,MAAM,KAAK,KAAK,KAAK;AACrC,UAAI,UAAU,QAAS,WAAU;AAAA,IACnC,WAAW,KAAK,SAAS;AACvB,UAAI,gBAAgB;AAClB,kBAAU,sBAAsB,cAAc;AAC9C,yBAAiB;AAAA,MACnB;AACA,gBAAU,MAAM,IAAI,KAAK,KAAK,KAAK;AACnC,UAAI,UAAU,MAAO,WAAU;AAAA,IACjC,OAAO;AACL,wBAAkB,KAAK;AAAA,IACzB;AAAA,EACF,CAAC;AAGD,MAAI,gBAAgB;AAClB,cAAU,sBAAsB,cAAc;AAAA,EAChD;AAEA,MAAI,QAAQ;AACV,YAAQ,IAAI,SAAS;AACrB,YAAQ,IAAI,SAAS,MAAM;AAAA,EAC7B,OAAO;AACL,YAAQ,IAAI,YAAY;AAAA,EAC1B;AACF;"} | ||
| {"version":3,"file":"logger.js","names":[],"sources":["../../src/logger.ts"],"sourcesContent":["import ansis from 'ansis'\nimport { diffWords } from 'diff'\n\nexport function logDiff(oldStr: string, newStr: string) {\n const differences = diffWords(oldStr, newStr)\n\n let output = ''\n let unchangedLines = ''\n\n function processUnchangedLines(lines: string): string {\n const lineArray = lines.split('\\n')\n if (lineArray.length > 4) {\n return [\n ansis.dim(lineArray[0]),\n ansis.dim(lineArray[1]),\n '',\n ansis.dim.bold(`... (${lineArray.length - 4} lines) ...`),\n '',\n ansis.dim(lineArray[lineArray.length - 2]),\n ansis.dim(lineArray[lineArray.length - 1]),\n ].join('\\n')\n }\n return ansis.dim(lines)\n }\n\n differences.forEach((part, index) => {\n const nextPart = differences[index + 1]\n\n if (part.added) {\n if (unchangedLines) {\n output += processUnchangedLines(unchangedLines)\n unchangedLines = ''\n }\n output += ansis.green.bold(part.value)\n if (nextPart?.removed) output += ' '\n } else if (part.removed) {\n if (unchangedLines) {\n output += processUnchangedLines(unchangedLines)\n unchangedLines = ''\n }\n output += ansis.red.bold(part.value)\n if (nextPart?.added) output += ' '\n } else {\n unchangedLines += part.value\n }\n })\n\n // Process any remaining unchanged lines at the end\n if (unchangedLines) {\n output += processUnchangedLines(unchangedLines)\n }\n\n if (output) {\n console.log('\\nDiff:')\n console.log(output + '\\n\\n')\n } else {\n console.log('No changes')\n }\n}\n"],"mappings":";;;AAGA,SAAgB,QAAQ,QAAgB,QAAgB;CACtD,MAAM,cAAc,UAAU,QAAQ,OAAO;CAE7C,IAAI,SAAS;CACb,IAAI,iBAAiB;CAErB,SAAS,sBAAsB,OAAuB;EACpD,MAAM,YAAY,MAAM,MAAM,KAAK;AACnC,MAAI,UAAU,SAAS,EACrB,QAAO;GACL,MAAM,IAAI,UAAU,GAAG;GACvB,MAAM,IAAI,UAAU,GAAG;GACvB;GACA,MAAM,IAAI,KAAK,QAAQ,UAAU,SAAS,EAAE,aAAa;GACzD;GACA,MAAM,IAAI,UAAU,UAAU,SAAS,GAAG;GAC1C,MAAM,IAAI,UAAU,UAAU,SAAS,GAAG;GAC3C,CAAC,KAAK,KAAK;AAEd,SAAO,MAAM,IAAI,MAAM;;AAGzB,aAAY,SAAS,MAAM,UAAU;EACnC,MAAM,WAAW,YAAY,QAAQ;AAErC,MAAI,KAAK,OAAO;AACd,OAAI,gBAAgB;AAClB,cAAU,sBAAsB,eAAe;AAC/C,qBAAiB;;AAEnB,aAAU,MAAM,MAAM,KAAK,KAAK,MAAM;AACtC,OAAI,UAAU,QAAS,WAAU;aACxB,KAAK,SAAS;AACvB,OAAI,gBAAgB;AAClB,cAAU,sBAAsB,eAAe;AAC/C,qBAAiB;;AAEnB,aAAU,MAAM,IAAI,KAAK,KAAK,MAAM;AACpC,OAAI,UAAU,MAAO,WAAU;QAE/B,mBAAkB,KAAK;GAEzB;AAGF,KAAI,eACF,WAAU,sBAAsB,eAAe;AAGjD,KAAI,QAAQ;AACV,UAAQ,IAAI,UAAU;AACtB,UAAQ,IAAI,SAAS,OAAO;OAE5B,SAAQ,IAAI,aAAa"} |
+1
-1
| { | ||
| "name": "@tanstack/router-utils", | ||
| "version": "1.161.5", | ||
| "version": "1.161.6", | ||
| "description": "Modern and scalable routing for React applications", | ||
@@ -5,0 +5,0 @@ "author": "Tanner Linsley", |
| {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"} |
| {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"} |
54760
3.48%673
0.15%29
-3.33%