Skip to content

Commit

Permalink
subpath imports for explicit 1:1 and concat prefix + suffix scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam McKee committed Nov 6, 2024
1 parent ca35659 commit b3bd003
Show file tree
Hide file tree
Showing 48 changed files with 1,073 additions and 218 deletions.
33 changes: 27 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [
[workspace.dependencies]
anyhow = "1.0.92"
serde = { version = "1.0.213", features = ["derive"] }
serde_json = "1.0.132"
serde_json = { version = "1.0.132", features = ["preserve_order"] }
swc = "4.0.0"
swc_common = { version = "3.0.0", features = ["concurrent"] }
swc_ecma_ast = "3.0.0"
Expand Down
4 changes: 2 additions & 2 deletions fn_build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ repository = { workspace = true }
[dependencies]
anyhow = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
swc = { workspace = true }
swc_common = { workspace = true }
swc_ecma_ast = { workspace = true }
swc_ecma_parser = { workspace = true }
swc_ecma_visit = { workspace = true }
thiserror = "1.0.67"
thiserror = "2.0.0"
tokio = { workspace = true }

[dev-dependencies]
serde_json = { workspace = true }
temp-dir = { workspace = true }
15 changes: 9 additions & 6 deletions fn_build/fixtures/swc/nodejs/js/http_route/.fixture/parse.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[
{
"imports": [],
"path": "routes/data/lambda.js"
}
]
{
"dependencies": "unused",
"sources": [
{
"imports": [],
"path": "routes/data/lambda.js"
}
]
}
31 changes: 17 additions & 14 deletions fn_build/fixtures/swc/nodejs/js/relative_import/.fixture/parse.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
[
{
"imports": [],
"path": "lib/data.js"
},
{
"imports": [
{
"relativeSource": "lib/data.js"
}
],
"path": "routes/data/lambda.js"
}
]
{
"dependencies": "unused",
"sources": [
{
"imports": [],
"path": "lib/data.js"
},
{
"imports": [
{
"relativeSource": "lib/data.js"
}
],
"path": "routes/data/lambda.js"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"path": "routes/data/lambda.js",
"result": "identical"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"path": "routes/data/lambda.js",
"result": {
"content": "import{getData as o}from\"#lib/data.js\";export const GET=()=>{console.log(\"got\",o())};"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"dependencies": "required",
"sources": [
{
"imports": [
{
"packageDependency": {
"package": "data-dep",
"subpath": null
}
}
],
"path": "routes/data/lambda.js"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"entrypoint": "routes/data/lambda.js"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "module",
"imports": {
"#lib/data.js": "data-dep"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {getData} from '#lib/data.js'

export const GET = () => {
console.log('got', getData())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"path": "lib/redis.js",
"result": "identical"
},
{
"path": "routes/data/lambda.js",
"result": "identical"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"path": "lib/redis.js",
"result": {
"content": "let t=[];export function getData(){return t}"
}
},
{
"path": "routes/data/lambda.js",
"result": {
"content": "import{getData as o}from\"#lib/data.js\";export const GET=()=>{console.log(\"got\",o())};"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"dependencies": "unused",
"sources": [
{
"imports": [],
"path": "lib/redis.js"
},
{
"imports": [
{
"relativeSource": "lib/redis.js"
}
],
"path": "routes/data/lambda.js"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"entrypoint": "routes/data/lambda.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const empty = []

export function getData() {
return empty
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "module",
"imports": {
"#lib/data.js": "./lib/redis.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {getData} from '#lib/data.js'

export const GET = () => {
console.log('got', getData())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"path": "data/raw.js",
"result": "identical"
},
{
"path": "data/abstraction/orm.js",
"result": "identical"
},
{
"path": "routes/data/lambda.js",
"result": "identical"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"path": "data/raw.js",
"result": {
"content": "let t=[];export function getData(){return t}"
}
},
{
"path": "data/abstraction/orm.js",
"result": {
"content": "let t=[[[]],[]];export function getComplexData(){return t}"
}
},
{
"path": "routes/data/lambda.js",
"result": {
"content": "import{getData as o}from\"#lib/data/raw.js\";import{getComplexData as t}from\"#lib/data/abstraction/orm.js\";export const GET=()=>{console.log(\"got\",o()),console.log(\"getting\",t())};"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"dependencies": "unused",
"sources": [
{
"imports": [],
"path": "data/raw.js"
},
{
"imports": [],
"path": "data/abstraction/orm.js"
},
{
"imports": [
{
"relativeSource": "data/raw.js"
},
{
"relativeSource": "data/abstraction/orm.js"
}
],
"path": "routes/data/lambda.js"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"entrypoint": "routes/data/lambda.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const architecturalDiagrams = [[[]], []]

export function getComplexData() {
return architecturalDiagrams
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const empty = []

export function getData() {
return empty
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"description": "mapping a concatenation wildcard subpath import",
"type": "module",
"imports": {
"#lib/data/*": "./data/*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {getData} from '#lib/data/raw.js'
import {getComplexData} from '#lib/data/abstraction/orm.js'

export const GET = () => {
console.log('got', getData())
console.log('getting', getComplexData())
}
Loading

0 comments on commit b3bd003

Please sign in to comment.