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
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Instructs the TypeScript compiler how to compile .ts files.",
|
"description": "Instructs the TypeScript compiler how to compile .ts files.",
|
||||||
@@ -71,7 +73,10 @@
|
|||||||
},
|
},
|
||||||
"declarationDir": {
|
"declarationDir": {
|
||||||
"description": "Specify the output directory for generated declaration files.",
|
"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"
|
"markdownDescription": "Specify the output directory for generated declaration files.\n\nSee more: https://www.typescriptlang.org/tsconfig#declarationDir"
|
||||||
},
|
},
|
||||||
"disableSizeLimit": {
|
"disableSizeLimit": {
|
||||||
@@ -140,7 +145,14 @@
|
|||||||
"jsx": {
|
"jsx": {
|
||||||
"description": "Specify what JSX code is generated.",
|
"description": "Specify what JSX code is generated.",
|
||||||
"type": "number",
|
"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"
|
"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": {
|
"keyofStringsOnly": {
|
||||||
@@ -306,19 +318,33 @@
|
|||||||
"module": {
|
"module": {
|
||||||
"description": "Specify what module code is generated.",
|
"description": "Specify what module code is generated.",
|
||||||
"type": "number",
|
"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"
|
"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": {
|
"moduleResolution": {
|
||||||
"description": "Specify how TypeScript looks up a file from a given module specifier.",
|
"description": "Specify how TypeScript looks up a file from a given module specifier.",
|
||||||
"type": "number",
|
"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"
|
"markdownDescription": "Specify how TypeScript looks up a file from a given module specifier.\n\n1 = Classic\n\n2 = NodeJs"
|
||||||
},
|
},
|
||||||
"newLine": {
|
"newLine": {
|
||||||
"description": "Set the newline character for emitting files.",
|
"description": "Set the newline character for emitting files.",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"enum": [0, 1],
|
"enum": [
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
],
|
||||||
"markdownDescription": "Set the newline character for emitting files.\n\n0 = CarriageReturnLineFeed\n\n1 = LineFeed"
|
"markdownDescription": "Set the newline character for emitting files.\n\n0 = CarriageReturnLineFeed\n\n1 = LineFeed"
|
||||||
},
|
},
|
||||||
"noEmit": {
|
"noEmit": {
|
||||||
@@ -560,7 +586,19 @@
|
|||||||
"description": "Set the JavaScript language version for emitted JavaScript and include compatible library declarations.",
|
"description": "Set the JavaScript language version for emitted JavaScript and include compatible library declarations.",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": 0,
|
"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"
|
"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": {
|
"traceResolution": {
|
||||||
@@ -604,7 +642,6 @@
|
|||||||
"default": false,
|
"default": false,
|
||||||
"markdownDescription": "Emit ECMAScript-standard-compliant class fields.\n\nSee more: https://www.typescriptlang.org/tsconfig#useDefineForClassFields"
|
"markdownDescription": "Emit ECMAScript-standard-compliant class fields.\n\nSee more: https://www.typescriptlang.org/tsconfig#useDefineForClassFields"
|
||||||
},
|
},
|
||||||
|
|
||||||
"allowArbitraryExtensions": {
|
"allowArbitraryExtensions": {
|
||||||
"description": "Enable importing files with any extension, provided a declaration file is present.",
|
"description": "Enable importing files with any extension, provided a declaration file is present.",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@@ -773,12 +810,20 @@
|
|||||||
},
|
},
|
||||||
"moduleDetection": {
|
"moduleDetection": {
|
||||||
"description": "Specify how TypeScript determine a file as module.",
|
"description": "Specify how TypeScript determine a file as module.",
|
||||||
"enum": ["auto", "legacy", "force"]
|
"enum": [
|
||||||
|
"auto",
|
||||||
|
"legacy",
|
||||||
|
"force"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"importsNotUsedAsValues": {
|
"importsNotUsedAsValues": {
|
||||||
"description": "Specify emit/checking behavior for imports that are only used for types.",
|
"description": "Specify emit/checking behavior for imports that are only used for types.",
|
||||||
"default": "remove",
|
"default": "remove",
|
||||||
"enum": ["remove", "preserve", "error"]
|
"enum": [
|
||||||
|
"remove",
|
||||||
|
"preserve",
|
||||||
|
"error"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"resolvePackageJsonExports": {
|
"resolvePackageJsonExports": {
|
||||||
"description": "Use the package.json 'exports' field when resolving package imports.",
|
"description": "Use the package.json 'exports' field when resolving package imports.",
|
||||||
@@ -819,3 +864,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user