diff --git a/examples/react-component/package.json b/examples/react-component/package.json index 01a562e5..0efe9370 100644 --- a/examples/react-component/package.json +++ b/examples/react-component/package.json @@ -4,8 +4,8 @@ "private": true, "description": "React Component Example.", "scripts": { - "watch": "tsbb watch src/*.{jsx,js,d.ts} --useBabel", - "build": "tsbb build src/*.{jsx,js,d.ts} --useBabel && npm run css:build && npm run css:build:dist", + "watch": "tsbb watch src/*.{jsx,js} --useBabel", + "build": "tsbb build src/*.{jsx,js} --useBabel && npm run css:build && npm run css:build:dist", "css:build": "compile-less -d src -o esm", "css:watch": "compile-less -d src -o esm --watch", "css:build:dist": "compile-less -d src --combine dist/markdown-editor.css --rm-global", diff --git a/examples/react-component/src/global.d.ts b/examples/react-component/src/global.d.ts new file mode 100644 index 00000000..48b9a9b2 --- /dev/null +++ b/examples/react-component/src/global.d.ts @@ -0,0 +1 @@ +export default function Demo3(): void; diff --git a/examples/react-component/src/good.json b/examples/react-component/src/good.json new file mode 100644 index 00000000..8d6b85c7 --- /dev/null +++ b/examples/react-component/src/good.json @@ -0,0 +1,3 @@ +{ + "a": 1 +} diff --git a/packages/core/src/watcher/babelTransform.ts b/packages/core/src/watcher/babelTransform.ts index cedac491..f50a04bf 100644 --- a/packages/core/src/watcher/babelTransform.ts +++ b/packages/core/src/watcher/babelTransform.ts @@ -11,36 +11,36 @@ export function babelTransform(options: CompileOptions = {}) { const rootDirsRelative = [...new Set(getRootsFolderName(options.entry))]; const entry = rootDirsRelative.map((item) => path.resolve(item)); const onFilesChange: CopyFilesOptions['onFilesChange'] = (eventName, filepath, stats) => { - if (/\.(m?js|jsx?|m?ts|tsx?|c?js)$/i.test(filepath)) { - const log = new Log().name(); - const dt = getOutputPath(filepath, options); - if (/^(add|change)$/.test(eventName) && !/\.d\.ts$/i.test(filepath)) { + const log = new Log().name(); + const dt = getOutputPath(filepath, options); + if (/\.(m?ts|m?js|jsx?|tsx?|c?js)(? \x1b[34;1m${dt.cjs.tsFileName}\x1b[0m`, - ); - } - if (typeof esm !== 'boolean') { - fs.ensureDirSync(path.dirname(dt.esm.path)); - fs.copyFile(filepath, dt.esm.path); - log - .icon('🐶') - .success( - `${getExt(filepath)}┈┈▶ \x1b[32;1m${dt.folderFilePath}\x1b[0m => \x1b[34;1m${dt.esm.tsFileName}\x1b[0m`, - ); - } } - if (/^(unlink|unlinkDir)$/.test(eventName)) { - fs.remove(dt.cjs.path); - fs.remove(dt.esm.path); - log.icon('🗑️').success(`┈┈▶ \x1b[32;1m${path.relative(process.cwd(), filepath)}\x1b[0m`); + } else if (/^(add|change)$/.test(eventName)) { + if (typeof cjs !== 'boolean') { + fs.ensureDirSync(path.dirname(dt.cjs.path)); + fs.copyFile(filepath, dt.cjs.path); + log + .icon('🐶') + .success( + `${getExt(filepath)}┈┈▶ \x1b[32;1m${dt.folderFilePath}\x1b[0m => \x1b[34;1m${dt.cjs.tsFileName}\x1b[0m`, + ); } + if (typeof esm !== 'boolean') { + fs.ensureDirSync(path.dirname(dt.esm.path)); + fs.copyFile(filepath, dt.esm.path); + log + .icon('🐶') + .success( + `${getExt(filepath)}┈┈▶ \x1b[32;1m${dt.folderFilePath}\x1b[0m => \x1b[34;1m${dt.esm.tsFileName}\x1b[0m`, + ); + } + } + if (/^(unlink|unlinkDir)$/.test(eventName)) { + fs.remove(dt.cjs.path); + fs.remove(dt.esm.path); + log.icon('🗑️').success(`┈┈▶ \x1b[32;1m${path.relative(process.cwd(), filepath)}\x1b[0m`); } }; const onReady = () => { diff --git a/packages/typescript/src/utils.ts b/packages/typescript/src/utils.ts index c9247a58..485e04ce 100644 --- a/packages/typescript/src/utils.ts +++ b/packages/typescript/src/utils.ts @@ -39,6 +39,7 @@ export const getExt = (extname: string) => { if (/^TS/.test(ext)) { return `\x1b[36;1m${ext}\x1b[0m`; } + return ext; }; export const getEmojiIcon = (fileName: string) => {