Skip to content

Commit cbd4670

Browse files
committedMar 29, 2023
fix: fix that files other than js cannot be copied in babel mode.
1 parent 1b49c9e commit cbd4670

File tree

5 files changed

+34
-29
lines changed

5 files changed

+34
-29
lines changed
 

‎examples/react-component/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"private": true,
55
"description": "React Component Example.",
66
"scripts": {
7-
"watch": "tsbb watch src/*.{jsx,js,d.ts} --useBabel",
8-
"build": "tsbb build src/*.{jsx,js,d.ts} --useBabel && npm run css:build && npm run css:build:dist",
7+
"watch": "tsbb watch src/*.{jsx,js} --useBabel",
8+
"build": "tsbb build src/*.{jsx,js} --useBabel && npm run css:build && npm run css:build:dist",
99
"css:build": "compile-less -d src -o esm",
1010
"css:watch": "compile-less -d src -o esm --watch",
1111
"css:build:dist": "compile-less -d src --combine dist/markdown-editor.css --rm-global",
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function Demo3(): void;
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"a": 1
3+
}

‎packages/core/src/watcher/babelTransform.ts

+27-27
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,36 @@ export function babelTransform(options: CompileOptions = {}) {
1111
const rootDirsRelative = [...new Set(getRootsFolderName(options.entry))];
1212
const entry = rootDirsRelative.map((item) => path.resolve(item));
1313
const onFilesChange: CopyFilesOptions['onFilesChange'] = (eventName, filepath, stats) => {
14-
if (/\.(m?js|jsx?|m?ts|tsx?|c?js)$/i.test(filepath)) {
15-
const log = new Log().name();
16-
const dt = getOutputPath(filepath, options);
17-
if (/^(add|change)$/.test(eventName) && !/\.d\.ts$/i.test(filepath)) {
14+
const log = new Log().name();
15+
const dt = getOutputPath(filepath, options);
16+
if (/\.(m?ts|m?js|jsx?|tsx?|c?js)(?<!\.d\.ts)$/i.test(filepath)) {
17+
if (/^(add|change)$/.test(eventName)) {
1818
babelCompile(filepath, { ...options });
19-
} else if (/\.d\.ts$/i.test(filepath)) {
20-
if (typeof cjs !== 'boolean') {
21-
fs.ensureDirSync(path.dirname(dt.cjs.path));
22-
fs.copyFile(filepath, dt.cjs.path);
23-
log
24-
.icon('🐶')
25-
.success(
26-
`${getExt(filepath)}┈┈▶ \x1b[32;1m${dt.folderFilePath}\x1b[0m => \x1b[34;1m${dt.cjs.tsFileName}\x1b[0m`,
27-
);
28-
}
29-
if (typeof esm !== 'boolean') {
30-
fs.ensureDirSync(path.dirname(dt.esm.path));
31-
fs.copyFile(filepath, dt.esm.path);
32-
log
33-
.icon('🐶')
34-
.success(
35-
`${getExt(filepath)}┈┈▶ \x1b[32;1m${dt.folderFilePath}\x1b[0m => \x1b[34;1m${dt.esm.tsFileName}\x1b[0m`,
36-
);
37-
}
3819
}
39-
if (/^(unlink|unlinkDir)$/.test(eventName)) {
40-
fs.remove(dt.cjs.path);
41-
fs.remove(dt.esm.path);
42-
log.icon('🗑️').success(`┈┈▶ \x1b[32;1m${path.relative(process.cwd(), filepath)}\x1b[0m`);
20+
} else if (/^(add|change)$/.test(eventName)) {
21+
if (typeof cjs !== 'boolean') {
22+
fs.ensureDirSync(path.dirname(dt.cjs.path));
23+
fs.copyFile(filepath, dt.cjs.path);
24+
log
25+
.icon('🐶')
26+
.success(
27+
`${getExt(filepath)}┈┈▶ \x1b[32;1m${dt.folderFilePath}\x1b[0m => \x1b[34;1m${dt.cjs.tsFileName}\x1b[0m`,
28+
);
4329
}
30+
if (typeof esm !== 'boolean') {
31+
fs.ensureDirSync(path.dirname(dt.esm.path));
32+
fs.copyFile(filepath, dt.esm.path);
33+
log
34+
.icon('🐶')
35+
.success(
36+
`${getExt(filepath)}┈┈▶ \x1b[32;1m${dt.folderFilePath}\x1b[0m => \x1b[34;1m${dt.esm.tsFileName}\x1b[0m`,
37+
);
38+
}
39+
}
40+
if (/^(unlink|unlinkDir)$/.test(eventName)) {
41+
fs.remove(dt.cjs.path);
42+
fs.remove(dt.esm.path);
43+
log.icon('🗑️').success(`┈┈▶ \x1b[32;1m${path.relative(process.cwd(), filepath)}\x1b[0m`);
4444
}
4545
};
4646
const onReady = () => {

‎packages/typescript/src/utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const getExt = (extname: string) => {
3939
if (/^TS/.test(ext)) {
4040
return `\x1b[36;1m${ext}\x1b[0m`;
4141
}
42+
return ext;
4243
};
4344

4445
export const getEmojiIcon = (fileName: string) => {

0 commit comments

Comments
 (0)
Please sign in to comment.