Open d9k opened 7 months ago
@deckchairlabs, @mashaal, do we have working example with alias?
Should have one
Entries for paths with aliases just not created in .ultra/importMap.browser.json
and importMap.server.json
at all!
Expected something like
"/~/": "/src/",
"./src/app.tsx": "/src/app/app.fe83edc4.js",
"/~/app/app.tsx": "/src/app/app.fe83edc4.js",
But no entries for app.fe83edc4.js
in .ultra/importMap.browser.json
Ultra uses mesozoic builder.
Aliases should be added to mesozoic test fixture
Wrote script which copies source code to subfolder and transforms absolute local imports with aliases to relative import there:
d9k/citations-supabase-demo: script/copy-and-transform-imports-to-relative.ts
const walkIterator = fs.walk(
PROJECT_COPY_WITH_IMPORTS_TRANSFORMED_TO_RELATIVE_PATH,
{
match: matchScriptsRegexArray,
},
);
for await (const scriptFileEntry of walkIterator) {
const scriptAbsPath = scriptFileEntry.path;
const scriptRelPath = path.relative(
PROJECT_COPY_WITH_IMPORTS_TRANSFORMED_TO_RELATIVE_PATH,
scriptAbsPath,
);
const scriptDirPath = path.dirname(scriptAbsPath);
console.debug('walk scripts:', scriptRelPath, scriptFileEntry.path);
const codeLines = Deno.readTextFileSync(scriptFileEntry.path);
const replaceQuotedPath: ReplaceCallback = (
_quotedPath,
importPathWithAlias,
) => {
console.debug(' ', importPathWithAlias);
const importPathAbs = importPathWithAlias.replace(/^\/~\//, () => {
return aliasSrcAbsPath + '/';
});
const importPathRelativeToScript = path.relative(
scriptDirPath,
importPathAbs,
);
const importPathRelativeToScriptStartsWithDot =
importPathRelativeToScript.match(/^\.\./)
? importPathRelativeToScript
: `./${importPathRelativeToScript}`;
return `'${importPathRelativeToScriptStartsWithDot}'`;
};
const transformStringWithQuotedPath = (stringWithQuotedPath: string) => {
const transformedString = stringWithQuotedPath.replace(
/'(.*)'/,
replaceQuotedPath,
);
console.debug('->', transformedString);
return transformedString;
};
const codeLinesWithRelImports = codeLines.replace(
/from[\s\n\r]+'\/~\/.*'/gm,
(fromWithQuotedPath) => {
console.debug(' ', fromWithQuotedPath);
return transformStringWithQuotedPath(fromWithQuotedPath);
},
/** async import */
).replace(/import\([\s\n\r]*'\/~\/.*'/gm, (fromWithQuotedPath) => {
console.debug(' ', fromWithQuotedPath);
return transformStringWithQuotedPath(fromWithQuotedPath);
});
Deno.writeTextFileSync(scriptAbsPath, codeLinesWithRelImports);
}
https://github.com/d9k/citations-supabase-demo/tree/726f3da7cf16698975bc4906a8274967c03f705b
Error highlight