diff --git a/package-lock.json b/package-lock.json index d2a172dc4..e9a6c08d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,6 +36,7 @@ "@types/he": "^1.2.3", "@types/node": "^20.12.5", "@types/sinon": "^17.0.3", + "@types/unzip-stream": "^0.3.4", "@types/yargs": "^17.0.32", "@ui5-language-assistant/semantic-model": "^3.3.1", "@ui5-language-assistant/semantic-model-types": "^3.3.1", @@ -50,7 +51,8 @@ "semver": "^7.6.0", "sinon": "^17.0.1", "tsx": "^4.7.2", - "typescript-eslint": "^7.5.0" + "typescript-eslint": "^7.5.0", + "unzip-stream": "^0.3.1" }, "engines": { "node": "^18.14.2 || ^20.11.0 || >=21.2.0", @@ -2786,6 +2788,15 @@ "resolved": "https://registry.npmjs.org/@types/three/-/three-0.125.3.tgz", "integrity": "sha512-tUPMzKooKDvMOhqcNVUPwkt+JNnF8ASgWSsrLgleVd0SjLj4boJhteSsF9f6YDjye0mmUjO+BDMWW83F97ehXA==" }, + "node_modules/@types/unzip-stream": { + "version": "0.3.4", + "resolved": "https://registry.npmjs.org/@types/unzip-stream/-/unzip-stream-0.3.4.tgz", + "integrity": "sha512-ud0vtsNRF+joUCyvNMyo0j5DKX2Lh/im+xVgRzBEsfHhQYZ+i4fKTveova9XxLzt6Jl6G0e/0mM4aC0gqZYSnA==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/yargs": { "version": "17.0.32", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", @@ -4066,6 +4077,19 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, + "node_modules/binary": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/binary/-/binary-0.3.0.tgz", + "integrity": "sha512-D4H1y5KYwpJgK8wk1Cue5LLPgmwHKYSChkbspQg5JtVuR5ulGckxfR62H3AE9UDkdMC8yyXlqYihuz3Aqg2XZg==", + "dev": true, + "dependencies": { + "buffers": "~0.1.1", + "chainsaw": "~0.1.0" + }, + "engines": { + "node": "*" + } + }, "node_modules/binary-extensions": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", @@ -4150,6 +4174,15 @@ "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" }, + "node_modules/buffers": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/buffers/-/buffers-0.1.1.tgz", + "integrity": "sha512-9q/rDEGSb/Qsvv2qvzIzdluL5k7AaJOTrw23z9reQthrbF7is4CtlT0DXyO1oei2DCp4uojjzQ7igaSHp1kAEQ==", + "dev": true, + "engines": { + "node": ">=0.2.0" + } + }, "node_modules/builtins": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/builtins/-/builtins-5.0.1.tgz", @@ -4342,6 +4375,18 @@ "node": ">=12.19" } }, + "node_modules/chainsaw": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/chainsaw/-/chainsaw-0.1.0.tgz", + "integrity": "sha512-75kWfWt6MEKNC8xYXIdRpDehRYY/tNSgwKaJq+dbbDcxORuVrrQ+SEHoWsniVn9XPYfP4gmdWIeDk/4YNp1rNQ==", + "dev": true, + "dependencies": { + "traverse": ">=0.3.0 <0.4" + }, + "engines": { + "node": "*" + } + }, "node_modules/chalk": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", @@ -11639,6 +11684,15 @@ "node": ">=8.0" } }, + "node_modules/traverse": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/traverse/-/traverse-0.3.9.tgz", + "integrity": "sha512-iawgk0hLP3SxGKDfnDJf8wTz4p2qImnyihM5Hh/sGvQ3K37dPi/w8sRhdNIxYA1TwFwc5mDhIJq+O0RsvXBKdQ==", + "dev": true, + "engines": { + "node": "*" + } + }, "node_modules/treeverse": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/treeverse/-/treeverse-3.0.0.tgz", @@ -11928,6 +11982,28 @@ "node": ">= 10.0.0" } }, + "node_modules/unzip-stream": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/unzip-stream/-/unzip-stream-0.3.1.tgz", + "integrity": "sha512-RzaGXLNt+CW+T41h1zl6pGz3EaeVhYlK+rdAap+7DxW5kqsqePO8kRtWPaCiVqdhZc86EctSPVYNix30YOMzmw==", + "dev": true, + "dependencies": { + "binary": "^0.3.0", + "mkdirp": "^0.5.1" + } + }, + "node_modules/unzip-stream/node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "dev": true, + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, "node_modules/update-browserslist-db": { "version": "1.0.13", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz", diff --git a/scripts/metadataProvider/createPseudoModulesInfo.ts b/scripts/metadataProvider/createPseudoModulesInfo.ts index 3e856763b..3fd4c5c93 100644 --- a/scripts/metadataProvider/createPseudoModulesInfo.ts +++ b/scripts/metadataProvider/createPseudoModulesInfo.ts @@ -1,9 +1,12 @@ import {pipeline} from "node:stream/promises"; import {Extract} from "unzip-stream"; import MetadataProvider from "./MetadataProvider.js"; -import {writeFile} from "node:fs/promises"; +import {writeFile, readdir} from "node:fs/promises"; +import {createRequire} from "module"; +const require = createRequire(import.meta.url); import type {UI5Enum, UI5EnumValue} from "@ui5-language-assistant/semantic-model-types"; +import path from "node:path"; const RAW_API_JSON_FILES_FOLDER = "tmp/apiJson"; @@ -20,13 +23,35 @@ async function downloadAPIJsons(url: string) { } } +async function extractPseudoModuleNames() { + const apiJsonList = await readdir(RAW_API_JSON_FILES_FOLDER); + + return apiJsonList.flatMap((library) => { + const libApiJson = require(path.resolve(RAW_API_JSON_FILES_FOLDER, library)); + return libApiJson.symbols; + }).reduce((acc: Record, symbol) => { + if (symbol.kind === "enum" && symbol.resource.endsWith("library.js")) { + acc[symbol.name] = true; + } + + return acc; + }, Object.create(null) as Record); +} + async function transformFiles() { const metadataProvider = new MetadataProvider(); - await metadataProvider.init(RAW_API_JSON_FILES_FOLDER); + await metadataProvider.init(RAW_API_JSON_FILES_FOLDER, "1.120.12" /** TODO: Extract it from URL */); + + const pseudoModuleNames = await extractPseudoModuleNames(); const {enums} = metadataProvider.getModel(); const groupedEnums = Object.keys(enums).reduce((acc: Record, enumKey: string) => { + // Filter only real pseudo modules i.e. defined within library.js files + if (!pseudoModuleNames[enumKey]) { + return acc; + } + const curEnum = enums[enumKey]; acc[curEnum.library] = acc[curEnum.library] ?? [];