diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 234f31fed..ebcf4aa31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: ${{ runner.os }}-${{ matrix.node-version }}-test- ${{ runner.os }}- - name: Install pnpm - run: npm i -g pnpm + run: corepack enable - name: Install deps run: pnpm i @@ -67,7 +67,7 @@ jobs: ${{ runner.os }}-${{ matrix.node-version }}-release-${{ env.cache-name }}- ${{ runner.os }}-${{ matrix.node-version }}-release- ${{ runner.os }}- - - run: npm i -g pnpm + - run: corepack enable - run: pnpm i - run: pnpx semantic-release --branches main env: diff --git a/package.json b/package.json index 68b264e09..7b786a28e 100644 --- a/package.json +++ b/package.json @@ -61,8 +61,10 @@ "resolve": "1.20.0", "rollup-plugin-dts": "5.3.0", "rollup-plugin-hashbang": "2.2.2", + "sass": "1.62.1", "strip-json-comments": "4.0.0", "svelte": "3.46.4", + "svelte-preprocess": "5.0.3", "terser": "^5.16.0", "ts-essentials": "9.1.2", "tsconfig-paths": "3.12.0", @@ -89,5 +91,6 @@ }, "engines": { "node": ">=16.14" - } + }, + "packageManager": "pnpm@8.6.0" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4e810ef3a..bf902a42e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -100,12 +100,18 @@ devDependencies: rollup-plugin-hashbang: specifier: 2.2.2 version: 2.2.2 + sass: + specifier: 1.62.1 + version: 1.62.1 strip-json-comments: specifier: 4.0.0 version: 4.0.0 svelte: specifier: 3.46.4 version: 3.46.4 + svelte-preprocess: + specifier: 5.0.3 + version: 5.0.3(postcss-load-config@4.0.1)(postcss@8.4.12)(sass@1.62.1)(svelte@3.46.4)(typescript@5.0.2) terser: specifier: ^5.16.0 version: 5.16.0 @@ -123,7 +129,7 @@ devDependencies: version: 5.0.2 vitest: specifier: 0.28.4 - version: 0.28.4(terser@5.16.0) + version: 0.28.4(sass@1.62.1)(terser@5.16.0) wait-for-expect: specifier: 3.0.2 version: 3.0.2 @@ -818,6 +824,10 @@ packages: resolution: {integrity: sha512-q4jlIR71hUpWTnGhXWcakgkZeHa3CCjcQcnuzU8M891BAWA2jHiziiWEPEkdS5pFsz7H9HJiy8BrK7tBRNrY7A==} dev: true + /@types/pug@2.0.6: + resolution: {integrity: sha512-SnHmG9wN1UVmagJOnyo/qkk0Z7gejYxOYYmaAwr5u2yFYfsupN3sg10kyzN8Hep/2zbHxCnsumxOoRIRMBwKCg==} + dev: true + /@types/resolve@1.20.1: resolution: {integrity: sha512-Ku5+GPFa12S3W26Uwtw+xyrtIpaZsGYHH6zxNbZlstmlvMYSZRzOwzwsXbxlVUbHyUucctSyuFtu6bNxwYomIw==} dev: true @@ -936,6 +946,10 @@ packages: dependencies: fill-range: 7.0.1 + /buffer-crc32@0.2.13: + resolution: {integrity: sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==} + dev: true + /buffer-from@1.1.2: resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} dev: true @@ -1089,6 +1103,11 @@ packages: type-detect: 4.0.8 dev: true + /detect-indent@6.1.0: + resolution: {integrity: sha512-reYkTUJAZb9gUuZ2RvVCNhVHdg62RHnJ7WJl8ftMi4diZ6NWlciOzQN88pUhSELEwflJht4oQDv0F0BMlwaYtA==} + engines: {node: '>=8'} + dev: true + /diff@5.1.0: resolution: {integrity: sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw==} engines: {node: '>=0.3.1'} @@ -1108,6 +1127,10 @@ packages: resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==} dev: true + /es6-promise@3.3.1: + resolution: {integrity: sha512-SOp9Phqvqn7jtEUxPWdWfWoLmyt2VaJ6MpvP9Comy1MceMXqE6bxvaTu4iaxpYYPzhny28Lc+M87/c2cPK6lDg==} + dev: true + /esbuild-android-64@0.14.50: resolution: {integrity: sha512-H7iUEm7gUJHzidsBlFPGF6FTExazcgXL/46xxLo6i6bMtPim6ZmXyTccS8yOMpy6HAC6dPZ/JCQqrkkin69n6Q==} engines: {node: '>=12'} @@ -1509,6 +1532,10 @@ packages: resolution: {integrity: sha512-2zeMQpbKz5dhZ9IwL0gbxSW5w0NK/MSAMtNuhgIHEPmaU3vPdKPL0UdvUCXs5SS4JAwsBxysK5sFMW8ocFiVjQ==} engines: {node: '>= 4'} + /immutable@4.3.0: + resolution: {integrity: sha512-0AOCmOip+xgJwEVTQj1EfiDDOkPmuyllDuTuEX+DDXUgapLAsBIfkg3sxCYyCEA8mQqZrrxPUGjcOQ2JS3WLkg==} + dev: true + /import-cwd@3.0.0: resolution: {integrity: sha512-4pnzH16plW+hgvRECbDWpQl3cqtvSofHWh44met7ESfZ8UZOWWddm8hEyDTqREJ9RbYHY8gi8DqmaelApoOGMg==} engines: {node: '>=8'} @@ -1612,7 +1639,6 @@ packages: /lilconfig@2.1.0: resolution: {integrity: sha512-utWOt/GHzuUxnLKxB6dk81RoOeoNeHgbrXiuGk4yyF5qlRz+iIVWu56E2fqGHFrXz0QNUhLB/8nKqvRH66JKGQ==} engines: {node: '>=10'} - dev: false /lines-and-columns@1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} @@ -1647,6 +1673,13 @@ packages: vlq: 0.2.3 dev: true + /magic-string@0.27.0: + resolution: {integrity: sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==} + engines: {node: '>=12'} + dependencies: + '@jridgewell/sourcemap-codec': 1.4.14 + dev: true + /magic-string@0.30.0: resolution: {integrity: sha512-LA+31JYDJLs82r2ScLrlz1GjSgu66ZV518eyWT+S8VhyQn/JL0u9MeBOvQMGYiPk1DBiSN9DDMOcXvigJZaViQ==} engines: {node: '>=12'} @@ -1672,6 +1705,11 @@ packages: resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} engines: {node: '>=6'} + /min-indent@1.0.1: + resolution: {integrity: sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==} + engines: {node: '>=4'} + dev: true + /minimatch@3.0.4: resolution: {integrity: sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==} dependencies: @@ -1681,6 +1719,17 @@ packages: resolution: {integrity: sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==} dev: true + /minimist@1.2.8: + resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} + dev: true + + /mkdirp@0.5.6: + resolution: {integrity: sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==} + hasBin: true + dependencies: + minimist: 1.2.8 + dev: true + /mlly@1.1.0: resolution: {integrity: sha512-cwzBrBfwGC1gYJyfcy8TcZU1f+dbH/T+TuOhtYP2wLv/Fb51/uV7HJQfBPtEupZ2ORLRU1EKFS/QfS3eo9+kBQ==} dependencies: @@ -1826,7 +1875,6 @@ packages: lilconfig: 2.1.0 postcss: 8.4.12 yaml: 2.3.1 - dev: false /postcss-simple-vars@6.0.3(postcss@8.4.12): resolution: {integrity: sha512-fkNn4Zio8vN4vIig9IFdb8lVlxWnYR769RgvxCM6YWlFKie/nQaOcaMMMFz/s4gsfHW4/5bJW+i57zD67mQU7g==} @@ -1910,6 +1958,13 @@ packages: resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} + /rimraf@2.7.1: + resolution: {integrity: sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==} + hasBin: true + dependencies: + glob: 7.1.6 + dev: true + /rollup-plugin-dts@5.3.0(rollup@3.8.1)(typescript@5.0.2): resolution: {integrity: sha512-8FXp0ZkyZj1iU5klkIJYLjIq/YZSwBoERu33QBDxm/1yw5UU4txrEtcmMkrq+ZiKu3Q4qvPCNqc3ovX6rjqzbQ==} engines: {node: '>=v14'} @@ -1951,6 +2006,25 @@ packages: dependencies: queue-microtask: 1.2.3 + /sander@0.5.1: + resolution: {integrity: sha512-3lVqBir7WuKDHGrKRDn/1Ye3kwpXaDOMsiRP1wd6wpZW56gJhsbp5RqQpA6JG/P+pkXizygnr1dKR8vzWaVsfA==} + dependencies: + es6-promise: 3.3.1 + graceful-fs: 4.2.8 + mkdirp: 0.5.6 + rimraf: 2.7.1 + dev: true + + /sass@1.62.1: + resolution: {integrity: sha512-NHpxIzN29MXvWiuswfc1W3I0N8SXBd8UR26WntmDlRYf0bSADnwnOjsyMZ3lMezSlArD33Vs3YFhp7dWvL770A==} + engines: {node: '>=14.0.0'} + hasBin: true + dependencies: + chokidar: 3.5.2 + immutable: 4.3.0 + source-map-js: 1.0.2 + dev: true + /shebang-command@2.0.0: resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} engines: {node: '>=8'} @@ -1980,6 +2054,16 @@ packages: is-fullwidth-code-point: 4.0.0 dev: true + /sorcery@0.11.0: + resolution: {integrity: sha512-J69LQ22xrQB1cIFJhPfgtLuI6BpWRiWu1Y3vSsIwK/eAScqJxd/+CJlUuHQRdX2C9NGFamq+KqNywGgaThwfHw==} + hasBin: true + dependencies: + '@jridgewell/sourcemap-codec': 1.4.14 + buffer-crc32: 0.2.13 + minimist: 1.2.5 + sander: 0.5.1 + dev: true + /source-map-js@1.0.2: resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==} engines: {node: '>=0.10.0'} @@ -2035,6 +2119,13 @@ packages: resolution: {integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==} engines: {node: '>=6'} + /strip-indent@3.0.0: + resolution: {integrity: sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==} + engines: {node: '>=8'} + dependencies: + min-indent: 1.0.1 + dev: true + /strip-json-comments@4.0.0: resolution: {integrity: sha512-LzWcbfMbAsEDTRmhjWIioe8GcDRl0fa35YMXFoJKDdiD/quGFmjJjdgPjFJJNwCMaLyQqFIDqCdHD2V4HfLgYA==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -2071,6 +2162,56 @@ packages: engines: {node: '>= 0.4'} dev: true + /svelte-preprocess@5.0.3(postcss-load-config@4.0.1)(postcss@8.4.12)(sass@1.62.1)(svelte@3.46.4)(typescript@5.0.2): + resolution: {integrity: sha512-GrHF1rusdJVbOZOwgPWtpqmaexkydznKzy5qIC2FabgpFyKN57bjMUUUqPRfbBXK5igiEWn1uO/DXsa2vJ5VHA==} + engines: {node: '>= 14.10.0'} + requiresBuild: true + peerDependencies: + '@babel/core': ^7.10.2 + coffeescript: ^2.5.1 + less: ^3.11.3 || ^4.0.0 + postcss: ^7 || ^8 + postcss-load-config: ^2.1.0 || ^3.0.0 || ^4.0.0 + pug: ^3.0.0 + sass: ^1.26.8 + stylus: ^0.55.0 + sugarss: ^2.0.0 || ^3.0.0 || ^4.0.0 + svelte: ^3.23.0 + typescript: '>=3.9.5 || ^4.0.0 || ^5.0.0' + peerDependenciesMeta: + '@babel/core': + optional: true + coffeescript: + optional: true + less: + optional: true + postcss: + optional: true + postcss-load-config: + optional: true + pug: + optional: true + sass: + optional: true + stylus: + optional: true + sugarss: + optional: true + typescript: + optional: true + dependencies: + '@types/pug': 2.0.6 + detect-indent: 6.1.0 + magic-string: 0.27.0 + postcss: 8.4.12 + postcss-load-config: 4.0.1(postcss@8.4.12) + sass: 1.62.1 + sorcery: 0.11.0 + strip-indent: 3.0.0 + svelte: 3.46.4 + typescript: 5.0.2 + dev: true + /svelte@3.46.4: resolution: {integrity: sha512-qKJzw6DpA33CIa+C/rGp4AUdSfii0DOTCzj/2YpSKKayw5WGSS624Et9L1nU1k2OVRS9vaENQXp2CVZNU+xvIg==} engines: {node: '>= 8'} @@ -2205,7 +2346,7 @@ packages: engines: {node: '>= 10.0.0'} dev: true - /vite-node@0.28.4(terser@5.16.0): + /vite-node@0.28.4(sass@1.62.1)(terser@5.16.0): resolution: {integrity: sha512-KM0Q0uSG/xHHKOJvVHc5xDBabgt0l70y7/lWTR7Q0pR5/MrYxadT+y32cJOE65FfjGmJgxpVEEY+69btJgcXOQ==} engines: {node: '>=v14.16.0'} hasBin: true @@ -2217,7 +2358,7 @@ packages: picocolors: 1.0.0 source-map: 0.6.1 source-map-support: 0.5.21 - vite: 3.0.3(terser@5.16.0) + vite: 3.0.3(sass@1.62.1)(terser@5.16.0) transitivePeerDependencies: - less - sass @@ -2226,7 +2367,7 @@ packages: - terser dev: true - /vite@3.0.3(terser@5.16.0): + /vite@3.0.3(sass@1.62.1)(terser@5.16.0): resolution: {integrity: sha512-sDIpIcl3mv1NUaSzZwiXGEy1ZoWwwC2vkxUHY6yiDacR6zf//ZFuBJrozO62gedpE43pmxnLATNR5IYUdAEkMQ==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true @@ -2249,12 +2390,13 @@ packages: postcss: 8.4.14 resolve: 1.22.1 rollup: 2.77.0 + sass: 1.62.1 terser: 5.16.0 optionalDependencies: fsevents: 2.3.2 dev: true - /vitest@0.28.4(terser@5.16.0): + /vitest@0.28.4(sass@1.62.1)(terser@5.16.0): resolution: {integrity: sha512-sfWIy0AdlbyGRhunm+TLQEJrFH9XuRPdApfubsyLcDbCRrUX717BRQKInTgzEfyl2Ipi1HWoHB84Nqtcwxogcg==} engines: {node: '>=v14.16.0'} hasBin: true @@ -2297,8 +2439,8 @@ packages: tinybench: 2.3.1 tinypool: 0.3.1 tinyspy: 1.1.0 - vite: 3.0.3(terser@5.16.0) - vite-node: 0.28.4(terser@5.16.0) + vite: 3.0.3(sass@1.62.1)(terser@5.16.0) + vite-node: 0.28.4(sass@1.62.1)(terser@5.16.0) why-is-node-running: 2.2.2 transitivePeerDependencies: - less @@ -2353,7 +2495,6 @@ packages: /yaml@2.3.1: resolution: {integrity: sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==} engines: {node: '>= 14'} - dev: false /yocto-queue@1.0.0: resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==} diff --git a/src/esbuild/svelte.ts b/src/esbuild/svelte.ts index dc2dcbbaf..0a3401833 100644 --- a/src/esbuild/svelte.ts +++ b/src/esbuild/svelte.ts @@ -16,6 +16,7 @@ export const sveltePlugin = ({ setup(build) { let svelte: typeof import('svelte/compiler') + let sveltePreprocessor: typeof import('svelte-preprocess').default build.onResolve({ filter: /\.svelte\.css$/ }, (args) => { return { @@ -29,6 +30,8 @@ export const sveltePlugin = ({ build.onLoad({ filter: /\.svelte$/ }, async (args) => { svelte = svelte || localRequire('svelte/compiler') + sveltePreprocessor = + sveltePreprocessor || localRequire('svelte-preprocess') if (!svelte) { return { @@ -60,27 +63,42 @@ export const sveltePlugin = ({ // Convert Svelte syntax to JavaScript try { - const preprocess = await svelte.preprocess(source, { - async script({ content, attributes }) { - if (attributes.lang !== 'ts') return { code: content } + const preprocess = await svelte.preprocess( + source, + sveltePreprocessor + ? sveltePreprocessor({ + sourceMap: true, + typescript: { + compilerOptions: { + preserveValueImports: true, + }, + }, + }) + : { + async script({ content, attributes }) { + if (attributes.lang !== 'ts') return { code: content } - const { code, map } = await transform(content, { - sourcefile: args.path, - loader: 'ts', - sourcemap: true, - tsconfigRaw: { - compilerOptions: { - preserveValueImports: true, + const { code, map } = await transform(content, { + sourcefile: args.path, + loader: 'ts', + sourcemap: true, + tsconfigRaw: { + compilerOptions: { + preserveValueImports: true, + }, + }, + logLevel: build.initialOptions.logLevel, + }) + return { + code, + map, + } }, }, - logLevel: build.initialOptions.logLevel, - }) - return { - code, - map, - } - }, - }) + { + filename: args.path, + } + ) const result = svelte.compile(preprocess.code, { filename, css: false, diff --git a/test/index.test.ts b/test/index.test.ts index c50a999ea..721c3f655 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -499,6 +499,24 @@ test('svelte: typescript support', async () => { expect(output).toContain('// Component.svelte') }) +test('svelte: sass support', async () => { + const { outFiles, output, getFileContent } = await run(getTestName(), { + 'input.ts': `import App from './App.svelte' + export { App } + `, + 'App.svelte': ` +