From 77f07d7f4f6eae13e6df72e7f7b2cffb3e7f15f2 Mon Sep 17 00:00:00 2001 From: Jeffrey Li Date: Thu, 17 Jun 2021 00:29:22 -0400 Subject: [PATCH] preprocess to ignore styles and handle typescript --- package.json | 3 ++- src/rollup-plugin.ts | 14 +++++++++++++- yarn.lock | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5408850..cf0b530 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "prettier": "^2.2.1", "rollup": "^2.36.0", "rollup-plugin-svelte": "^7.0.0", - "svelte": "^3.31.2" + "svelte": "^3.31.2", + "svelte-preprocess": "^4.7.3" }, "devDependencies": { "@types/fs-extra": "^9.0.6", diff --git a/src/rollup-plugin.ts b/src/rollup-plugin.ts index 88036d4..0fe8bb1 100644 --- a/src/rollup-plugin.ts +++ b/src/rollup-plugin.ts @@ -7,6 +7,8 @@ import writeMarkdown, { WriteMarkdownOptions } from "./writer/writer-markdown"; import ComponentParser, { ParsedComponent } from "./ComponentParser"; import { getSvelteEntry } from "./get-svelte-entry"; import { ParsedExports, parseExports } from "./parse-exports"; +import { preprocess } from "svelte/compiler"; +import { replace, typescript } from "svelte-preprocess"; export interface PluginSveldOptions { glob?: boolean; @@ -77,10 +79,20 @@ export async function generateBundle(input: string, glob: boolean) { if (ext === '.svelte') { const source = await fs.readFile(path.resolve(dir, filePath), "utf-8"); + + const { code: processed } = await preprocess( + source, + [ + typescript(), + replace([[//gims, ""]]), + ], + { filename: path.basename(filePath) } + ); + components.set(moduleName, { moduleName, filePath, - ...parser.parseSvelteComponent(source, { + ...parser.parseSvelteComponent(processed, { moduleName, filePath, }), diff --git a/yarn.lock b/yarn.lock index d07ccef..422b599 100644 --- a/yarn.lock +++ b/yarn.lock @@ -71,6 +71,11 @@ resolved "https://registry.npmjs.org/@types/prettier/-/prettier-2.1.6.tgz#f4b1efa784e8db479cdb8b14403e2144b1e9ff03" integrity sha512-6gOkRe7OIioWAXfnO/2lFiv+SJichKVSys1mSsgyrYHSEjk8Ctv4tSR/Odvnu+HWlH2C8j53dahU03XmQdd5fA== +"@types/pug@^2.0.4": + version "2.0.4" + resolved "https://registry.yarnpkg.com/@types/pug/-/pug-2.0.4.tgz#8772fcd0418e3cd2cc171555d73007415051f4b2" + integrity sha1-h3L80EGOPNLMFxVV1zAHQVBR9LI= + "@types/resolve@1.17.1": version "1.17.1" resolved "https://registry.npmjs.org/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6" @@ -78,6 +83,13 @@ dependencies: "@types/node" "*" +"@types/sass@^1.16.0": + version "1.16.0" + resolved "https://registry.yarnpkg.com/@types/sass/-/sass-1.16.0.tgz#b41ac1c17fa68ffb57d43e2360486ef526b3d57d" + integrity sha512-2XZovu4NwcqmtZtsBR5XYLw18T8cBCnU2USFHTnYLLHz9fkhnoEMoDsqShJIOFsFhn5aJHjweiUUdTrDGujegA== + dependencies: + "@types/node" "*" + "@types/strip-bom@^3.0.0": version "3.0.0" resolved "https://registry.yarnpkg.com/@types/strip-bom/-/strip-bom-3.0.0.tgz#14a8ec3956c2e81edb7520790aecf21c290aebd2" @@ -313,6 +325,11 @@ defined@^1.0.0: resolved "https://registry.npmjs.org/defined/-/defined-1.0.0.tgz#c98d9bcef75674188e110969151199e39b1fa693" integrity sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM= +detect-indent@^6.0.0: + version "6.1.0" + resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-6.1.0.tgz#592485ebbbf6b3b1ab2be175c8393d04ca0d57e6" + integrity sha512-reYkTUJAZb9gUuZ2RvVCNhVHdg62RHnJ7WJl8ftMi4diZ6NWlciOzQN88pUhSELEwflJht4oQDv0F0BMlwaYtA== + diff@^4.0.1: version "4.0.2" resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" @@ -804,6 +821,11 @@ micromatch@^4.0.2: braces "^3.0.1" picomatch "^2.0.5" +min-indent@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/min-indent/-/min-indent-1.0.1.tgz#a63f681673b30571fbe8bc25686ae746eefa9869" + integrity sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg== + minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" @@ -1239,6 +1261,13 @@ strip-indent@^1.0.1: dependencies: get-stdin "^4.0.1" +strip-indent@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-3.0.0.tgz#c32e1cee940b6b3432c771bc2c54bcce73cd3001" + integrity sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ== + dependencies: + min-indent "^1.0.0" + strip-json-comments@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" @@ -1251,6 +1280,16 @@ supports-color@^5.3.0: dependencies: has-flag "^3.0.0" +svelte-preprocess@^4.7.3: + version "4.7.3" + resolved "https://registry.yarnpkg.com/svelte-preprocess/-/svelte-preprocess-4.7.3.tgz#454fa059c2400b15e7a3caeca18993cff9df0e96" + integrity sha512-Zx1/xLeGOIBlZMGPRCaXtlMe4ZA0faato5Dc3CosEqwu75MIEPuOstdkH6cy+RYTUYynoxzNaDxkPX4DbrPwRA== + dependencies: + "@types/pug" "^2.0.4" + "@types/sass" "^1.16.0" + detect-indent "^6.0.0" + strip-indent "^3.0.0" + svelte@^3.31.2: version "3.31.2" resolved "https://registry.npmjs.org/svelte/-/svelte-3.31.2.tgz#d2ddf6cacbb95e4cc3796207510b660a25586324"