Skip to content

Commit

Permalink
fix: fix that files other than js cannot be copied in babel mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 29, 2023
1 parent 1b49c9e commit cbd4670
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
4 changes: 2 additions & 2 deletions examples/react-component/package.json
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions examples/react-component/src/global.d.ts
@@ -0,0 +1 @@
export default function Demo3(): void;
3 changes: 3 additions & 0 deletions examples/react-component/src/good.json
@@ -0,0 +1,3 @@
{
"a": 1
}
54 changes: 27 additions & 27 deletions packages/core/src/watcher/babelTransform.ts
Expand Up @@ -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)(?<!\.d\.ts)$/i.test(filepath)) {
if (/^(add|change)$/.test(eventName)) {
babelCompile(filepath, { ...options });
} else if (/\.d\.ts$/i.test(filepath)) {
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`);
} 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 = () => {
Expand Down
1 change: 1 addition & 0 deletions packages/typescript/src/utils.ts
Expand Up @@ -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) => {
Expand Down

0 comments on commit cbd4670

Please sign in to comment.