Skip to content

Commit

Permalink
build: change build type by api-extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
1ncounter committed Mar 26, 2024
1 parent ea96be3 commit c7a483f
Show file tree
Hide file tree
Showing 21 changed files with 179 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ packages/*/lib/
packages/*/es/
packages/*/dist/
packages/*/output/
packages/*/temp/
packages/demo/
package-lock.json
yarn.lock
Expand Down
54 changes: 54 additions & 0 deletions api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",

"mainEntryPointFilePath": "<projectFolder>/temp/index.d.ts",

"compiler": {
"tsconfigFilePath": "<projectFolder>/tsconfig.declaration.json"
},

"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "",
"publicTrimmedFilePath": "<projectFolder>/dist/index.d.ts"
},

"apiReport": {
"enabled": false
},

"docModel": {
"enabled": false
},
"tsdocMetadata": {
"enabled": false
},

"messages": {
"compilerMessageReporting": {
"default": {
"logLevel": "warning"
}
},

"tsdocMessageReporting": {
"default": {
"logLevel": "none"
}
},

"extractorMessageReporting": {
"default": {
"logLevel": "warning"
},

"ae-missing-release-tag": {
"logLevel": "none"
},

"ae-extra-release-tag": {
"logLevel": "none"
}
}
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@alilc/build-plugin-lce": "^0.0.5",
"@alilc/lowcode-test-mate": "^1.0.1",
"@changesets/cli": "^2.27.1",
"@microsoft/api-extractor": "^7.43.0",
"@types/node": "^20.11.30",
"@types/react-router": "5.1.18",
"@vitejs/plugin-react": "^4.2.1",
Expand All @@ -48,8 +49,7 @@
"rimraf": "^5.0.2",
"rollup": "^4.13.0",
"vite": "^5.1.6",
"vitest": "^1.3.1",
"vite-plugin-dts": "^3.7.3"
"vitest": "^1.3.1"
},
"engines": {
"node": ">=18"
Expand Down
8 changes: 7 additions & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
"module": "dist/lowcodeTypes.js",
"types": "dist/index.d.ts",
"exports": {
".": "./dist/lowcodeTypes.js"
".": {
"import": "./dist/lowcodeTypes.js",
"module": "./dist/lowcodeTypes.js",
"types": "./dist/index.d.ts"
},
"./package.json": "./package.json"
},
"files": [
"dist",
Expand All @@ -16,6 +21,7 @@
],
"scripts": {
"build": "vite build",
"build-dts": "tsc -p tsconfig.declaration.json && node ../../scripts/rollup-dts.mjs",
"test": "vitest"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/event/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export interface EventConfig {
[eventName: string]: any;
}

export type { Node };
export { Node };
2 changes: 1 addition & 1 deletion packages/types/src/event/node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Prop from './prop';

export type { Prop };
export { Prop };

export interface RerenderOptions {
time: number;
Expand Down
9 changes: 9 additions & 0 deletions packages/types/tsconfig.declaration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": true,
"declaration": true,
"outDir": "temp",
"stripInternal": true
}
}
3 changes: 3 additions & 0 deletions packages/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"]
}
9 changes: 0 additions & 9 deletions packages/types/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineConfig } from 'vite';
import { resolve } from 'node:path';
import dts from 'vite-plugin-dts';

export default defineConfig({
build: {
Expand All @@ -13,12 +12,4 @@ export default defineConfig({
fileName: 'lowcodeTypes',
},
},
plugins: [
dts({
rollupTypes: true,
compilerOptions: {
stripInternal: true,
},
}),
],
});
7 changes: 6 additions & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": "./dist/lowCodeUtils.js"
".": {
"import": "./dist/lowCodeUtils.js",
"types": "./dist/index.d.ts"
},
"./package.json": "./package.json"
},
"sideEffects": [
"*.css"
Expand All @@ -19,6 +23,7 @@
],
"scripts": {
"build": "vite build",
"build-dts": "tsc -p tsconfig.declaration.json && node ../../scripts/rollup-dts.mjs",
"test": "vitest"
},
"dependencies": {
Expand Down
10 changes: 10 additions & 0 deletions packages/utils/tsconfig.declaration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": true,
"declaration": true,
"outDir": "temp",
"stripInternal": true,
"paths": {}
}
}
1 change: 1 addition & 0 deletions packages/utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"paths": {
"@alilc/lowcode-*": ["packages/*"]
}
Expand Down
1 change: 1 addition & 0 deletions packages/utils/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default defineConfig({
react(),
dts({
rollupTypes: true,
tsconfigPath: resolve(import.meta.dirname, 'tsconfig.declaration.json'),
compilerOptions: {
stripInternal: true,
paths: {},
Expand Down
6 changes: 5 additions & 1 deletion runtime/renderer-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
"module": "dist/rendererCore.js",
"types": "dist/index.d.ts",
"exports": {
".": "./dist/rendererCore.js"
".": {
"import": "./dist/rendererCore.js",
"types": "./dist/index.d.ts"
}
},
"files": [
"dist",
Expand All @@ -19,6 +22,7 @@
],
"scripts": {
"build": "vite build",
"build-dts": "tsc -p tsconfig.declaration.json && node ../../scripts/rollup-dts.mjs",
"test": "vitest --run",
"test:watch": "vitest"
},
Expand Down
9 changes: 9 additions & 0 deletions runtime/renderer-core/tsconfig.declaration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": true,
"declaration": true,
"outDir": "temp",
"stripInternal": true
}
}
4 changes: 3 additions & 1 deletion runtime/renderer-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
"exports": {
".": {
"import": "./dist/rendererReact.js",
"require": "./dist/rendererReact.cjs"
"require": "./dist/rendererReact.cjs",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"build": "vite build",
"build-dts": "tsc -p tsconfig.declaration.json && node ../../scripts/rollup-dts.mjs",
"test": "vitest"
},
"dependencies": {
Expand Down
9 changes: 9 additions & 0 deletions runtime/renderer-react/tsconfig.declaration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": true,
"declaration": true,
"outDir": "temp",
"stripInternal": true
}
}
6 changes: 5 additions & 1 deletion runtime/router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
"module": "dist/runtimeRouter.js",
"types": "dist/index.d.ts",
"exports": {
".": "./dist/runtimeRouter.js"
".": {
"import": "./dist/runtimeRouter.js",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"build": "vite build",
"build-dts": "tsc -p tsconfig.declaration.json && node ../../scripts/rollup-dts.mjs",
"test": "vitest"
},
"dependencies": {
Expand Down
9 changes: 9 additions & 0 deletions runtime/router/tsconfig.declaration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": true,
"declaration": true,
"outDir": "temp",
"stripInternal": true
}
}
43 changes: 43 additions & 0 deletions scripts/rollup-dts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { join } from 'node:path';
import { existsSync, readdirSync } from 'node:fs';
import { Extractor, ExtractorConfig } from '@microsoft/api-extractor';
import { rimraf } from 'rimraf';

const libPath = process.env.PWD;
const packages = readdirSync(join(libPath, 'temp/packages'));
const typeTempIndexPath = join(libPath, 'temp/packages', packages[0], 'src/index.d.ts');

if (!existsSync(typeTempIndexPath)) {
console.error('🚨类型入口路径错误');
process.exit(1);
}

async function run() {
const configObject = ExtractorConfig.loadFile('../../api-extractor.json');
configObject.mainEntryPointFilePath = typeTempIndexPath;

const extractorConfig = ExtractorConfig.prepare({
configObject,
projectFolderLookupToken: libPath,
packageJsonFullPath: join(libPath, 'package.json'),
});

const extractorResult = Extractor.invoke(extractorConfig, {
localBuild: true,
showVerboseMessages: true,
});

if (extractorResult.succeeded) {
console.log(`🚀类型声明文件生成成功!!!`);

await rimraf(join(libPath, 'temp'));
} else {
console.error(
'🚨类型声明文件生成失败:' +
+`\n\t${extractorResult.errorCount} errors``\n\tand ${extractorResult.warningCount} warnings`,
);
process.exit(1);
}
}

run();
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"compilerOptions": {
"declaration": true,
"lib": ["DOM", "ESNext", "DOM.Iterable"],
// Target latest version of ECMAScript.
"target": "esnext",
Expand Down

0 comments on commit c7a483f

Please sign in to comment.