Skip to content

Commit d421ab7

Browse files
committedSep 3, 2021
fix(tsbb): Fix reference errors.
1 parent 804fdef commit d421ab7

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed
 

‎example/basic/tsconfig.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
"module": "commonjs",
44
"esModuleInterop": true,
55
"declaration": true,
6-
"target": "ES2017",
6+
"target": "es2017",
77
"noImplicitAny": true,
88
"resolveJsonModule": true,
9-
"strict": false,
9+
"moduleResolution": "node",
1010
"emitDecoratorMetadata": true,
1111
"experimentalDecorators": true,
1212
"sourceMap": true,
13+
"strict": false,
1314
"skipLibCheck": true,
15+
"outDir": "lib",
1416
"baseUrl": "."
1517
},
16-
"include": ["src/**/*"],
17-
"exclude": ["lib", "esm"]
18+
"include": ["src/**/*"]
1819
}

‎packages/tsbb/src/utils/compile.ts

+25-23
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,28 @@ export async function compile(
2323
const dirToFiles = await recursiveReaddirFiles(path.dirname(entry), {
2424
exclude: /(tsconfig.json|.(test|spec).(ts|tsx|js|jsx))$/,
2525
});
26-
await Promise.all(
27-
dirToFiles.map(async (item) => {
28-
if (disableBabel) {
29-
return;
30-
}
31-
if (cjs) {
32-
const cjsPath = item.path.replace(entryDir, cjs);
33-
if (isMatch(item.path, ['**/*.[jt]s?(x)']) && !isMatch(item.path, ['**/?(*.)+(spec|test).[jt]s?(x)', '**/*.d.ts'])) {
34-
transform(item.path, { entryDir, cjs, ...other });
35-
} else {
36-
copyFiles(item.path, cjsPath);
26+
if (!disableBabel) {
27+
await Promise.all(
28+
dirToFiles.map(async (item) => {
29+
if (cjs) {
30+
const cjsPath = item.path.replace(entryDir, cjs);
31+
if (isMatch(item.path, ['**/*.[jt]s?(x)']) && !isMatch(item.path, ['**/?(*.)+(spec|test).[jt]s?(x)'])) {
32+
transform(item.path, { entryDir, cjs, ...other });
33+
} else {
34+
copyFiles(item.path, cjsPath);
35+
}
3736
}
38-
}
39-
if (esm) {
40-
const esmPath = item.path.replace(entryDir, esm);
41-
if (isMatch(item.path, ['**/*.[jt]s?(x)']) && !isMatch(item.path, ['**/?(*.)+(spec|test).[jt]s?(x)', '**/*.d.ts'])) {
42-
transform(item.path, { entryDir, esm, ...other });
43-
} else {
44-
copyFiles(item.path, esmPath);
37+
if (esm) {
38+
const esmPath = item.path.replace(entryDir, esm);
39+
if (isMatch(item.path, ['**/*.[jt]s?(x)']) && !isMatch(item.path, ['**/?(*.)+(spec|test).[jt]s?(x)'])) {
40+
transform(item.path, { entryDir, esm, ...other });
41+
} else {
42+
copyFiles(item.path, esmPath);
43+
}
4544
}
46-
}
47-
}),
48-
);
45+
}),
46+
);
47+
}
4948

5049
// Create a Program with an in-memory emit
5150
const createdFiles: Record<string, string> = {};
@@ -57,11 +56,14 @@ export async function compile(
5756

5857
const host = ts.createCompilerHost(tsOptions, true);
5958
// ts.getParsedCommandLineOfConfigFile('', tsOptions, host)
60-
const files: string[] = [];
6159
host.readFile = (file) => {
6260
const result = ts.sys.readFile(file);
6361
if (!/node_modules/.test(file)) {
64-
files.push(file);
62+
// const output = path.resolve(tsOptions.outDir || cjs, path.relative(entryDir, file));
63+
// const outputLib = path.relative(process.cwd(), output);
64+
// if (/.d.ts$/.test(outputLib)) {
65+
// createdFiles[outputLib] = result;
66+
// }
6567
}
6668
return result;
6769
};

‎packages/tsbb/src/utils/watchCompile.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ export async function watchCompile(
3030
watcher.on('change', async (filepath) => {
3131
if (esm) {
3232
const output = filepath.replace(entryDir, esm);
33-
if (!disableBabel && isMatch(output, ['**/*.[jt]s?(x)']) && !isMatch(output, ['**/?(*.)+(spec|test).[jt]s?(x)'])) {
33+
if (!disableBabel && isMatch(output, ['**/*.[jt]s?(x)']) && !isMatch(output, ['**/?(*.)+(spec|test).[jt]s?(x)', '**/?(*.)+d.ts'])) {
3434
transform(filepath, { entryDir, esm, ...other });
35-
} else if (!isMatch(output, ['**/?(*.)+(spec|test).[jt]s?(x)', 'tsconfig.json'])) {
35+
} else if (!isMatch(output, ['**/?(*.)+(spec|test).[jt]s?(x)', 'tsconfig.json', '**/?(*.)+d.ts'])) {
3636
const result = ts.sys.readFile(filepath);
3737
outputFiles(output, result);
3838
}
3939
}
4040
if (cjs) {
4141
const output = filepath.replace(entryDir, cjs);
42-
if (!disableBabel && isMatch(output, ['**/*.[jt]s?(x)']) && !isMatch(output, ['**/?(*.)+(spec|test).[jt]s?(x)'])) {
42+
if (!disableBabel && isMatch(output, ['**/*.[jt]s?(x)']) && !isMatch(output, ['**/?(*.)+(spec|test).[jt]s?(x)', '**/?(*.)+d.ts'])) {
4343
transform(filepath, { entryDir, cjs, ...other });
44-
} else if (!isMatch(output, ['**/?(*.)+(spec|test).[jt]s?(x)', 'tsconfig.json'])) {
44+
} else if (!isMatch(output, ['**/?(*.)+(spec|test).[jt]s?(x)', 'tsconfig.json', '**/?(*.)+d.ts'])) {
4545
const result = ts.sys.readFile(filepath);
4646
outputFiles(output, result);
4747
}

0 commit comments

Comments
 (0)
Please sign in to comment.