Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 0183d3b

Browse files
author
Je
committed
refactor: move Import comonent to link.ts
1 parent 9af658d commit 0183d3b

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

link.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { Children, cloneElement, CSSProperties, isValidElement, MouseEven
22
import { redirect } from './aleph.ts'
33
import events from './events.ts'
44
import { useRouter } from './hooks.ts'
5-
import util from './util.ts'
5+
import util, { reModuleExt, reStyleModuleExt } from './util.ts'
66

77
interface LinkProps {
88
to: string
@@ -140,3 +140,13 @@ export function NavLink({
140140

141141
return React.createElement(Link, { ...rest, to })
142142
}
143+
144+
export function Import(props: { from: string, props?: Record<string, any> }) {
145+
if (reStyleModuleExt.test(props.from)) {
146+
return null
147+
}
148+
if (reModuleExt.test(props.from)) {
149+
// todo: import component form props.__url
150+
return null
151+
}
152+
}

mod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ export { redirect } from './aleph.ts'
22
export * from './context.ts'
33
export { Head, SEO, Viewport } from './head.ts'
44
export * from './hooks.ts'
5-
export { Link, NavLink } from './link.ts'
6-
export const Import = (_: { from: string }) => null
5+
export { Import, Link, NavLink } from './link.ts'
6+

project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,12 +1028,12 @@ export class Project {
10281028
path.dirname(url),
10291029
dep.url.replace(reModuleExt, '')
10301030
)
1031-
mod.jsContent = mod.jsContent.replace(/(import|Import|export)([^'"]*)("|')([^'"]+)("|')(\)|;)?/g, (s, key, from, ql, importPath, qr, end) => {
1031+
mod.jsContent = mod.jsContent.replace(/(import|Import|export)([\s\S]*?)(from\s*=?\s*|\()("|')([^'"]+)("|')(\)|;)?/g, (s, key, fields, from, ql, importPath, qr, end) => {
10321032
if (
10331033
reHashJs.test(importPath) &&
10341034
importPath.slice(0, importPath.length - (hashShort + 4)) === depImportPath
10351035
) {
1036-
return `${key}${from}${ql}${depImportPath}.${dep.hash.slice(0, hashShort)}.js${qr}${end || ''}`
1036+
return `${key}${fields}${from}${ql}${depImportPath}.${dep.hash.slice(0, hashShort)}.js${qr}${end || ''}`
10371037
}
10381038
return s
10391039
})

0 commit comments

Comments
 (0)