Refactor(json schema): Optimize import map json schema
This commit is contained in:
@@ -125,13 +125,13 @@ class Compiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = importMap.imports[args.path]
|
let path = importMap[args.path]
|
||||||
let tempPath = args.path
|
let tempPath = args.path
|
||||||
while (!path && tempPath.includes('/')) {
|
while (!path && tempPath.includes('/')) {
|
||||||
tempPath = tempPath.substring(0, tempPath.lastIndexOf('/'))
|
tempPath = tempPath.substring(0, tempPath.lastIndexOf('/'))
|
||||||
if (importMap.imports[tempPath]) {
|
if (importMap[tempPath]) {
|
||||||
const suffix = args.path.replace(tempPath, '')
|
const suffix = args.path.replace(tempPath, '')
|
||||||
const importUrl = new URL(importMap.imports[tempPath])
|
const importUrl = new URL(importMap[tempPath])
|
||||||
path = `${importUrl.origin}${importUrl.pathname}${suffix}${importUrl.search}`
|
path = `${importUrl.origin}${importUrl.pathname}${suffix}${importUrl.search}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,7 +140,7 @@ class Compiler {
|
|||||||
}
|
}
|
||||||
const pathUrl = new URL(path)
|
const pathUrl = new URL(path)
|
||||||
const externals = pathUrl.searchParams.get('external')?.split(',') ?? []
|
const externals = pathUrl.searchParams.get('external')?.split(',') ?? []
|
||||||
Object.keys(importMap.imports).forEach((item) => {
|
Object.keys(importMap).forEach((item) => {
|
||||||
if (!(item in externals)) {
|
if (!(item in externals)) {
|
||||||
externals.push(item)
|
externals.push(item)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,18 +126,12 @@ export const tsconfigJsonDiagnosticsOptions: DiagnosticsOptions = {
|
|||||||
{
|
{
|
||||||
uri: 'tsconfig.json',
|
uri: 'tsconfig.json',
|
||||||
fileMatch: ['tsconfig.json'],
|
fileMatch: ['tsconfig.json'],
|
||||||
schema: {
|
schema: tsconfigSchema
|
||||||
type: 'object',
|
|
||||||
properties: tsconfigSchema
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
uri: 'import-map.json',
|
uri: 'import-map.json',
|
||||||
fileMatch: ['import-map.json'],
|
fileMatch: ['import-map.json'],
|
||||||
schema: {
|
schema: importMapSchema
|
||||||
type: 'object',
|
|
||||||
properties: importMapSchema
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
{
|
{
|
||||||
"imports": {
|
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Import map"
|
"additionalProperties": {"type": "string"}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ const Playground = ({
|
|||||||
try {
|
try {
|
||||||
setImportMap(JSON.parse(importMapRaw) as IImportMap)
|
setImportMap(JSON.parse(importMapRaw) as IImportMap)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setImportMap({ imports: {} })
|
setImportMap({})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!tsconfig) {
|
if (!tsconfig) {
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ export interface IFiles {
|
|||||||
[key: string]: IFile
|
[key: string]: IFile
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IImportMap {
|
export type IImportMap = Record<string, string>
|
||||||
imports: Record<string, string>
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ITsconfig {
|
export interface ITsconfig {
|
||||||
compilerOptions: CompilerOptions
|
compilerOptions: CompilerOptions
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user