diff --git a/.changeset/rare-dots-accept.md b/.changeset/rare-dots-accept.md new file mode 100644 index 00000000..3fdf42a2 --- /dev/null +++ b/.changeset/rare-dots-accept.md @@ -0,0 +1,5 @@ +--- +'vite-plugin-stripper': patch +--- + +using vite Plugin hook filters (rolldown opti) diff --git a/.prettierignore b/.prettierignore index d9037335..4042d7da 100644 --- a/.prettierignore +++ b/.prettierignore @@ -23,3 +23,5 @@ templates/ ab.d.ts .astro .VSCodeCounter/ +.all-contributorsrc +README.md diff --git a/packages/vite-plugin-stripper/src/lib/plugin.ts b/packages/vite-plugin-stripper/src/lib/plugin.ts index 2d4d803e..eeb884d5 100644 --- a/packages/vite-plugin-stripper/src/lib/plugin.ts +++ b/packages/vite-plugin-stripper/src/lib/plugin.ts @@ -139,52 +139,63 @@ export function stripper(options?: ViteStripperOptions): PluginOption { } }, - transform: async (code, filepath, option) => { - // Don't transform server-side code - if (option?.ssr) { - return - } - // files are only in ts - if (!filepath.endsWith('.ts')) { - return - } - - const allInfos: string[] = [] - let code_ast: string | ParseResult = code + transform: { + filter: { + id: /\.ts$/, + }, + async handler(code, id, option) { + // Don't transform server-side code + if (option?.ssr) { + return + } + // files are only in ts + // https://vite.dev/guide/rolldown#hook-filter-feature + // To make your plugin backward compatible with the older versions, make sure to also run the filter inside the hook handlers. + if (!id.endsWith('.ts')) { + return + } - if (options && options?.nullify && options.nullify.length > 0) { - const { info, code_ast: transformed } = await nullifyImports(code_ast, options.nullify) + const allInfos: string[] = [] + let code_ast: string | ParseResult = code - // Update the code for later transforms & return it - code_ast = transformed - allInfos.push(...info) - } + if (options && options?.nullify && options.nullify.length > 0) { + const { info, code_ast: transformed } = await nullifyImports(code_ast, options.nullify) - if (options && options?.strip && options.strip.length > 0) { - const { info, code_ast: transformed } = await transformStrip(code_ast, options.strip) + // Update the code for later transforms & return it + code_ast = transformed + allInfos.push(...info) + } - // Update the code for later transforms & return it - code_ast = transformed - allInfos.push(...info) - } + if (options && options?.strip && options.strip.length > 0) { + const { info, code_ast: transformed } = await transformStrip(code_ast, options.strip) - if (allInfos.length > 0) { - const toRet = print(code_ast) - - if (options?.debug) { - log.info( - `${gray('File:')} ${yellow(filepath)}\n` + - `${green('-----')}\n` + - `${toRet.code}` + - `\n${green(':::::')}\n` + - `${allInfos.join('\n')}` + - `\n${green('-----')}\n`, - ) + // Update the code for later transforms & return it + code_ast = transformed + allInfos.push(...info) } - return toRet - } + if (allInfos.length > 0) { + const toRet = print(code_ast) + + if (options?.debug) { + log.info( + `${gray('File:')} ${yellow(id)}\n` + + `${green('-----')}\n` + + `${toRet.code}` + + `\n${green(':::::')}\n` + + `${allInfos.join('\n')}` + + `\n${green('-----')}\n`, + ) + } + + return toRet + } + }, }, + + // transform: async (code, id, option) => { + + // }, }, ] diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 05ca1ebb..77fdbd9c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -188,7 +188,7 @@ catalogs: version: 5.8.2 vite: vite: - specifier: ^6.2.1 + specifier: ^6.3.5 version: 6.3.5 patchedDependencies: diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 34c85688..9ea8ffed 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -21,7 +21,7 @@ catalogs: 'tsx': '4.19.3' vite: - 'vite': '^6.2.1' + 'vite': '^6.3.5' testing: # unit @@ -91,18 +91,3 @@ catalogs: astro-icon: 1.1.5 sharp: 0.34.1 prettier-plugin-astro: 0.14.1 - conflicts_tsx_: - tsx: '' - conflicts_tsx_4_19_3: - tsx: 4.19.3 - conflicts_tooling_c: - tsx: c - conflicts_tooling_ca: - tsx: ca - conflicts_tooling_cat: - tsx: cat - conflicts_tooling_cata: - tsx: cata -catalog: - ts-node: ^10.9.2 - tsx: ^4.19.3