Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support root src path("@/":"./src/") #243

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ahuigo
Copy link
Contributor

@ahuigo ahuigo commented Feb 6, 2023

feat: support root src path("@/":"/_ultra/compiler/src/")

  1. Support root src path like import Button from '@/components/button.tsx'
  2. Add an example and test case about root src path in examples/with-react/router

Refer: https://nextjs.org/docs/advanced-features/module-path-aliases

@ahuigo ahuigo force-pushed the feat/root-src-path branch 3 times, most recently from fc9f35a to 34f05af Compare February 7, 2023 03:59
1. Support root src path like `import "@/config.ts"`
2. Add an example and test case about root src path in **examples/with-react/router**
@deckchairlabs
Copy link
Member

Does this also work when building?

@ahuigo
Copy link
Contributor Author

ahuigo commented Feb 7, 2023

Does this also work when building?

There are some issues related to Mesozoic to handle.

Since mesozic doesn't support external source like "utlra/":"../../".(refer to https://github.com/deckchairlabs/mesozoic/blob/main/lib/builder.ts#L317)

So, I want to extend mesozic's gatherSources() like this:

// build.test.ts
const sourcesRoot = await builder.gatherSources(root);
const sourcesExternal = await builder.gatherSources('../../', {ignore:[
     "./examples",
      "./.git",
]});
const sources = builder.mergeSources(sourcesRoot, sourcesExternal, ....)

What do you think of this?

@ahuigo
Copy link
Contributor Author

ahuigo commented Feb 16, 2023

And there is an another bug (refer to: https://github.com/deckchairlabs/mesozoic/blob/main/lib/builder.ts#L168).
I'll try to fix this.

import {
  parse as parseImportMap,
  resolve as importMapResolve,
} from "https://esm.sh/v106/@import-maps/[email protected]/resolve.js";
const d={
    imports:{
        "ultra/": "../../",
        "ultra-url/": "https://denopkg.com/exhibitionist-digital/ultra@main/",
    }
}
// bad
let m = parseImportMap(d, new URL("file:///home/myuser/ultra/examples/with-react-router"))
console.log('bad:',m.imports[`ultra/`]+'')
m = parseImportMap(d, new URL("file:///home/myuser/ultra/examples/with-react-router/"))
console.log('good1:',m.imports[`ultra/`]+'')
console.log('good2:',m.imports[`ultra-url/`]+'')
/**
 output:
    bad: file:///home/myuser/
    good1: file:///home/myuser/ultra/
    good2: https://denopkg.com/exhibitionist-digital/ultra@main/
 */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants