Refactor(json schema): Optimize import map json schema

This commit is contained in:
2024-10-26 16:59:45 +08:00
parent bb1895762e
commit bab85382d4
6 changed files with 858 additions and 822 deletions

View File

@@ -125,13 +125,13 @@ class Compiler {
}
}
let path = importMap.imports[args.path]
let path = importMap[args.path]
let tempPath = args.path
while (!path && tempPath.includes('/')) {
tempPath = tempPath.substring(0, tempPath.lastIndexOf('/'))
if (importMap.imports[tempPath]) {
if (importMap[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}`
}
}
@@ -140,7 +140,7 @@ class Compiler {
}
const pathUrl = new URL(path)
const externals = pathUrl.searchParams.get('external')?.split(',') ?? []
Object.keys(importMap.imports).forEach((item) => {
Object.keys(importMap).forEach((item) => {
if (!(item in externals)) {
externals.push(item)
}

View File

@@ -126,18 +126,12 @@ export const tsconfigJsonDiagnosticsOptions: DiagnosticsOptions = {
{
uri: 'tsconfig.json',
fileMatch: ['tsconfig.json'],
schema: {
type: 'object',
properties: tsconfigSchema
}
schema: tsconfigSchema
},
{
uri: 'import-map.json',
fileMatch: ['import-map.json'],
schema: {
type: 'object',
properties: importMapSchema
}
schema: importMapSchema
}
]
}

View File

@@ -1,6 +1,4 @@
{
"imports": {
"type": "object",
"description": "Import map"
}
"additionalProperties": {"type": "string"}
}

View File

@@ -34,7 +34,7 @@ const Playground = ({
try {
setImportMap(JSON.parse(importMapRaw) as IImportMap)
} catch (e) {
setImportMap({ imports: {} })
setImportMap({})
}
}
if (!tsconfig) {

View File

@@ -14,9 +14,7 @@ export interface IFiles {
[key: string]: IFile
}
export interface IImportMap {
imports: Record<string, string>
}
export type IImportMap = Record<string, string>
export interface ITsconfig {
compilerOptions: CompilerOptions

View File

@@ -1,4 +1,6 @@
{
"type": "object",
"properties": {
"compilerOptions": {
"type": "object",
"description": "Instructs the TypeScript compiler how to compile .ts files.",
@@ -71,7 +73,10 @@
},
"declarationDir": {
"description": "Specify the output directory for generated declaration files.",
"type": ["string", "null"],
"type": [
"string",
"null"
],
"markdownDescription": "Specify the output directory for generated declaration files.\n\nSee more: https://www.typescriptlang.org/tsconfig#declarationDir"
},
"disableSizeLimit": {
@@ -140,7 +145,14 @@
"jsx": {
"description": "Specify what JSX code is generated.",
"type": "number",
"enum": [0, 1, 2, 3, 4, 5],
"enum": [
0,
1,
2,
3,
4,
5
],
"markdownDescription": "Specify what JSX code is generated.\n\n0 = none\n\n1 = preserve\n\n2 = react\n\n3 = react-native\n\n4 = react-jsx\n\n5 = react-jsxdev"
},
"keyofStringsOnly": {
@@ -306,19 +318,33 @@
"module": {
"description": "Specify what module code is generated.",
"type": "number",
"enum": [0, 1, 2, 3, 4, 5, 99],
"enum": [
0,
1,
2,
3,
4,
5,
99
],
"markdownDescription": "Specify what module code is generated.\n\n0 = None\n\n1 = CommonJS\n\n2 = AMD\n\n3 = UMD\n\n4 = System\n\n5 = ES2015\n\n99 = ESNext"
},
"moduleResolution": {
"description": "Specify how TypeScript looks up a file from a given module specifier.",
"type": "number",
"enum": [1, 2],
"enum": [
1,
2
],
"markdownDescription": "Specify how TypeScript looks up a file from a given module specifier.\n\n1 = Classic\n\n2 = NodeJs"
},
"newLine": {
"description": "Set the newline character for emitting files.",
"type": "number",
"enum": [0, 1],
"enum": [
0,
1
],
"markdownDescription": "Set the newline character for emitting files.\n\n0 = CarriageReturnLineFeed\n\n1 = LineFeed"
},
"noEmit": {
@@ -560,7 +586,19 @@
"description": "Set the JavaScript language version for emitted JavaScript and include compatible library declarations.",
"type": "number",
"default": 0,
"enum": [0, 1, 2, 3, 4, 5, 6, 7, 99, 100, 99],
"enum": [
0,
1,
2,
3,
4,
5,
6,
7,
99,
100,
99
],
"markdownDescription": "Set the JavaScript language version for emitted JavaScript and include compatible library declarations.\n\n0 = ES3\n\n1 = ES5\n\n2 = ES2015\n\n3 = ES2016\n\n4 = ES2017\n\n5 = ES2018\n\n6 = ES2019\n\n7 = ES2020\n\n99 = ESNext\n\n100 = JSON\n\n99 = Latest"
},
"traceResolution": {
@@ -604,7 +642,6 @@
"default": false,
"markdownDescription": "Emit ECMAScript-standard-compliant class fields.\n\nSee more: https://www.typescriptlang.org/tsconfig#useDefineForClassFields"
},
"allowArbitraryExtensions": {
"description": "Enable importing files with any extension, provided a declaration file is present.",
"type": "boolean",
@@ -773,12 +810,20 @@
},
"moduleDetection": {
"description": "Specify how TypeScript determine a file as module.",
"enum": ["auto", "legacy", "force"]
"enum": [
"auto",
"legacy",
"force"
]
},
"importsNotUsedAsValues": {
"description": "Specify emit/checking behavior for imports that are only used for types.",
"default": "remove",
"enum": ["remove", "preserve", "error"]
"enum": [
"remove",
"preserve",
"error"
]
},
"resolvePackageJsonExports": {
"description": "Use the package.json 'exports' field when resolving package imports.",
@@ -818,4 +863,5 @@
}
}
}
}
}