Skip to content

Commit 555e8df

Browse files
sebavanMike Bond
authored andcommitted
fix build
1 parent 12eef7f commit 555e8df

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/dev/buildTools/src/addJSToCompiledFiles.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ function ProcessSource(sourceCode: string, forceMJS: boolean) {
88
const extension = forceMJS ? ".mjs" : ".js";
99
return (
1010
sourceCode
11+
// replace imports from directories with index.js (mixins are generating them)
12+
.replace(/import\("([./]+)"\)/g, `import("$1/index${extension}")`)
1113
// replace imports and exports with js extensions
1214
.replace(/((import|export).*["'](@babylonjs\/.*\/|\.{1,2}\/)((?!\.scss|\.svg|\.png|\.jpg).)*?)("|');/g, `$1${extension}$5;`)
1315
.replace(/((import|export)\(["']((@babylonjs\/.*\/|\.{1,2}\/)((?!\.scss|\.svg|\.png|\.jpg).)*?))(["'])\)/g, `$1${extension}$6)`)

packages/dev/buildTools/src/generateDeclaration.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ function GetModuleDeclaration(
7676
line = line.startsWith(" ") ? " //" + line.substring(3) : "// " + line;
7777
}
7878

79+
// replace type imports from directories with index (mixins are generating them)
80+
line = line.replace(/import\("([./]+)"\)/g, `import("$1/index")`);
81+
7982
[
8083
// Declaration
8184
/declare module ['"](.*)['"]/,
@@ -85,15 +88,17 @@ function GetModuleDeclaration(
8588
/ {4}module ['"](.*)['"]/,
8689
/^module ['"](\..*)['"]/,
8790
// Inlined Import
88-
/import\(['"](.*)['"]/,
91+
/import\(['"]([^'"]*)['"]/,
8992
// Side Effect Import
9093
/import ['"](.*)['"]/,
9194
].forEach((regex) => {
9295
const match = line.match(regex);
9396
if (match) {
9497
if (match[1][0] === ".") {
9598
const newLocation = path.join(sourceDir, match[1]).replace(/\\/g, "/");
96-
line = line.replace(match[1], newLocation);
99+
// replaceAll only avaialable by modifying the typescript lib
100+
// which we prefered to not change for now
101+
line = (line as any).replaceAll(match[1], newLocation);
97102
} else {
98103
let found = false;
99104
Object.keys(mapping).forEach((devPackageName) => {
@@ -319,8 +324,8 @@ function GetPackageDeclaration(
319324
while (i < lines.length) {
320325
let line = lines[i];
321326

322-
if (/import\("\.(.*)\)./g.test(line) && !/^declare type (.*) import/g.test(line)) {
323-
line = line.replace(/import\((.*)\)./, "");
327+
if (/import\("\.([^)]*)\)./g.test(line) && !/^declare type (.*) import/g.test(line)) {
328+
line = line.replace(/import\(([^)]*)\)./g, "");
324329
}
325330

326331
if (!line.includes("const enum") && !line.includes("=")) {

0 commit comments

Comments
 (0)