diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a44aa95030f..4e08aa9b8ff 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -756,13 +756,13 @@ importers: '@cspell/cspell-bundled-dicts': workspace:* cspell-lib: workspace:* import-fresh: ^3.3.0 - magic-string: ^0.27.0 + magic-string: ^0.29.0 dependencies: '@cspell/cspell-bundled-dicts': link:../../../packages/cspell-bundled-dicts import-fresh: 3.3.0 devDependencies: cspell-lib: link:../../../packages/cspell-lib - magic-string: 0.27.0 + magic-string: 0.29.0 test-packages/cspell-lib/test-cspell-lib-webpack: specifiers: diff --git a/test-packages/cspell-lib/test-cspell-lib-rollup/package.json b/test-packages/cspell-lib/test-cspell-lib-rollup/package.json index 41c266a1934..644bd5bd3c5 100644 --- a/test-packages/cspell-lib/test-cspell-lib-rollup/package.json +++ b/test-packages/cspell-lib/test-cspell-lib-rollup/package.json @@ -11,7 +11,7 @@ "scripts": { "clean": "shx rm -rf dist .tsbuildinfo", "build": "pnpm build:plugin && pnpm build:rollup", - "build:plugin": "tsc -p tsconfig.plugin.json", + "build:plugin": "tsc -p plugin/tsconfig.json", "build:rollup": "rollup -c rollup.config.mjs", "clean-build": "pnpm run clean && pnpm run build", "compile": "tsc -p .", @@ -27,7 +27,7 @@ }, "devDependencies": { "cspell-lib": "workspace:*", - "magic-string": "^0.27.0" + "magic-string": "^0.29.0" }, "main": "dist/index.cjs", "module": "dist/index.mjs", diff --git a/test-packages/cspell-lib/test-cspell-lib-rollup/plugin/index.mjs b/test-packages/cspell-lib/test-cspell-lib-rollup/plugin/index.mjs new file mode 100644 index 00000000000..bbfeb2dd2e8 --- /dev/null +++ b/test-packages/cspell-lib/test-cspell-lib-rollup/plugin/index.mjs @@ -0,0 +1 @@ +export { injectDirname } from './dist/rollup-plugin-inject-dirname.mjs'; diff --git a/test-packages/cspell-lib/test-cspell-lib-rollup/plugin/inject.d.mts b/test-packages/cspell-lib/test-cspell-lib-rollup/plugin/inject.d.mts new file mode 100644 index 00000000000..950ab430336 --- /dev/null +++ b/test-packages/cspell-lib/test-cspell-lib-rollup/plugin/inject.d.mts @@ -0,0 +1,8 @@ +export function injectSnippet( + code, + pos, + codeSnippet +): { + code: string; + map: { mappings: string }; +}; diff --git a/test-packages/cspell-lib/test-cspell-lib-rollup/plugin/inject.mjs b/test-packages/cspell-lib/test-cspell-lib-rollup/plugin/inject.mjs new file mode 100644 index 00000000000..468e26c4361 --- /dev/null +++ b/test-packages/cspell-lib/test-cspell-lib-rollup/plugin/inject.mjs @@ -0,0 +1,17 @@ +// eslint-disable-next-line node/no-unpublished-import +import MagicString from 'magic-string'; + +export function injectSnippet(code, pos, codeSnippet) { + const ms = new MagicString(code); + + const newCode = ms.appendLeft(pos, codeSnippet); + + const map = newCode.generateMap(); + + return { + code: newCode.toString(), + map: { + mappings: map.mappings, + }, + }; +} diff --git a/test-packages/cspell-lib/test-cspell-lib-rollup/src/plugin/rollup-plugin-inject-dirname.mts b/test-packages/cspell-lib/test-cspell-lib-rollup/plugin/src/rollup-plugin-inject-dirname.mts similarity index 79% rename from test-packages/cspell-lib/test-cspell-lib-rollup/src/plugin/rollup-plugin-inject-dirname.mts rename to test-packages/cspell-lib/test-cspell-lib-rollup/plugin/src/rollup-plugin-inject-dirname.mts index 9e2b2c8e817..77b0a41b844 100644 --- a/test-packages/cspell-lib/test-cspell-lib-rollup/src/plugin/rollup-plugin-inject-dirname.mts +++ b/test-packages/cspell-lib/test-cspell-lib-rollup/plugin/src/rollup-plugin-inject-dirname.mts @@ -1,7 +1,7 @@ /* eslint-disable node/no-extraneous-import */ import type { Plugin } from 'rollup'; -import MagicString from './magic-string.mjs'; +import { injectSnippet } from '../inject.mjs'; const codeSnippet = `\ import {fileURLToPath as $$inject_fileURLToPath} from 'url'; @@ -10,7 +10,7 @@ const __filename = $$inject_fileURLToPath(import.meta.url); const __dirname = $$inject_dirname(__filename); `; -export default function injectDirname(): Plugin { +export function injectDirname(): Plugin { return { name: 'inject-dirname', renderChunk: { @@ -21,8 +21,15 @@ export default function injectDirname(): Plugin { const ms = inject(code); if (!ms) return; - const sm = ms.generateMap(); - return { code: ms.toString(), map: sm }; + return { + code: ms.code, + map: { + ...ms.map, + names: [], + sources: [], + version: 1, + }, + }; }, }, writeBundle: { @@ -36,13 +43,11 @@ export default function injectDirname(): Plugin { }; } -function inject(code: string): MagicString | undefined { +function inject(code: string) { const pos = calcPosition(code); if (pos === undefined) return undefined; - const ms = new MagicString(code); - - return ms.appendLeft(pos, codeSnippet); + return injectSnippet(code, pos, codeSnippet); } function calcPosition(code: string): number | undefined { diff --git a/test-packages/cspell-lib/test-cspell-lib-rollup/plugin/tsconfig.json b/test-packages/cspell-lib/test-cspell-lib-rollup/plugin/tsconfig.json new file mode 100644 index 00000000000..8b1dd36346f --- /dev/null +++ b/test-packages/cspell-lib/test-cspell-lib-rollup/plugin/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../../tsconfig.esm.json", + "compilerOptions": { + "outDir": "dist", + "allowJs": true + }, + "include": [ + "src" + ] +} diff --git a/test-packages/cspell-lib/test-cspell-lib-rollup/rollup.config.mjs b/test-packages/cspell-lib/test-cspell-lib-rollup/rollup.config.mjs index c10501f88da..2c8f7d08712 100644 --- a/test-packages/cspell-lib/test-cspell-lib-rollup/rollup.config.mjs +++ b/test-packages/cspell-lib/test-cspell-lib-rollup/rollup.config.mjs @@ -4,7 +4,7 @@ import rollupPluginTypescript from '@rollup/plugin-typescript'; import rollupPluginJson from '@rollup/plugin-json'; import rollupPluginCommonjs from '@rollup/plugin-commonjs'; import { readFileSync } from 'fs'; -import injectDirname from './dist/plugin/rollup-plugin-inject-dirname.mjs'; +import { injectDirname } from './plugin/index.mjs'; const pkg = JSON.parse(readFileSync('./package.json', 'utf-8')); @@ -67,7 +67,7 @@ const configs = [ ...common, output: [ { ...common.output, file: pkg.main, format: 'cjs' }, - { ...common.output, file: pkg.module, format: 'es', globals: { MyGlobalValueJason: '$$filename_Jason$$' } }, + { ...common.output, file: pkg.module, format: 'es' }, ], plugins: getPlugins(), }, diff --git a/test-packages/cspell-lib/test-cspell-lib-rollup/src/plugin/magic-string.mts b/test-packages/cspell-lib/test-cspell-lib-rollup/src/plugin/magic-string.mts deleted file mode 100644 index 65c6501e5d0..00000000000 --- a/test-packages/cspell-lib/test-cspell-lib-rollup/src/plugin/magic-string.mts +++ /dev/null @@ -1,19 +0,0 @@ -/* eslint-disable node/no-unpublished-import */ -/* eslint-disable @typescript-eslint/no-misused-new */ -import type { MagicStringOptions, SourceMap, SourceMapOptions } from 'magic-string'; -import MS from 'magic-string'; - -export interface MagicString { - new (str: string, options?: MagicStringOptions): MagicString; - generateMap(options?: SourceMapOptions): SourceMap; - /** - * Appends the specified content at the index in the original string. - * If a range *ending* with index is subsequently moved, the insert will be moved with it. - * See also `s.prependLeft(...)`. - */ - appendLeft(index: number, content: string): MagicString; - toString(): string; -} -export const MagicString = MS as unknown as MagicString; - -export default MagicString; diff --git a/test-packages/cspell-lib/test-cspell-lib-rollup/tsconfig.json b/test-packages/cspell-lib/test-cspell-lib-rollup/tsconfig.json index a9d9e8969a6..58604489b14 100644 --- a/test-packages/cspell-lib/test-cspell-lib-rollup/tsconfig.json +++ b/test-packages/cspell-lib/test-cspell-lib-rollup/tsconfig.json @@ -1,7 +1,8 @@ { "extends": "../../../tsconfig.esm.json", "compilerOptions": { - "outDir": "dist" + "outDir": "dist", + "allowJs": true }, "include": [ "src" diff --git a/test-packages/cspell-lib/test-cspell-lib-rollup/tsconfig.plugin.json b/test-packages/cspell-lib/test-cspell-lib-rollup/tsconfig.plugin.json deleted file mode 100644 index 7ee748fc341..00000000000 --- a/test-packages/cspell-lib/test-cspell-lib-rollup/tsconfig.plugin.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../../tsconfig.esm.json", - "compilerOptions": { - "outDir": "dist/plugin" - }, - "include": [ - "src/plugin/*.mts" - ] -}