Skip to content

Commit

Permalink
support @types/cc-ambient-types (#16215)
Browse files Browse the repository at this point in the history
* support @types/cc-ambient-types

* optimize build workflow

* fix compile-native-ts workflow

* fix build native ts
  • Loading branch information
PPpro authored Sep 11, 2023
1 parent 131e84c commit 471fe46
Show file tree
Hide file tree
Showing 29 changed files with 167 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/native-ts-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci --ignore-scripts
- run: npm ci
- run: npx gulp build-debug-infos
- name: Download external
run: |
Expand Down
7 changes: 2 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,11 @@ gulp.task('build-h5-minified', gulp.series('build-debug-infos', async () => {

gulp.task('build-declarations', async () => {
const outDir = ps.join('bin', '.declarations');
const { build } = require('@cocos/build-engine/lib/build-declarations');
const { dtsBundler } = require('@cocos/ccbuild');
await fs.emptyDir(outDir);
return await build({
return await dtsBundler.build({
engine: __dirname,
outDir,
withIndex: true,
withExports: false,
withEditorExports: true,
});
});

Expand Down
20 changes: 16 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@
],
"scripts": {
"server": "http-server . -p 8002 -o playground/index.html",
"postinstall": "turbo build && gulp build-debug-infos && npm run build-declaration && npm run bundle-adapter && npm run fetch-ral",
"build": "gulp build",
"postinstall": "npm run build",
"build": "turbo build && npm run build-root",
"build-root": "gulp build-debug-infos && gulp build-declarations && npm run bundle-adapter && npm run fetch-ral",
"build:dev": "gulp build-h5-source",
"build:min": "gulp build-h5-minified",
"build-declaration": "npm run build-const && gulp build-declarations",
"build-api-json": "gulp build-api-json -i index.ts -o ./3d-api-docs/tempJson",
"build-api": "npm run build-api-json && gulp build-3d-api -i index.ts -o ./3d-api-docs -j ./3d-api-docs/tempJson",
"checkout-engine-version": "node ./scripts/checkout-engine-version.js",
"varify-engine-version": "node ./scripts/varify-engine-version.js",
"fetch-ral": "node ./scripts/fetch-ral.js",
"bundle-adapter": "node ./scripts/bundle-adapter.js",
"build-const": "node ./scripts/build-consts.js",
"clear": "node ./scripts/clear-cache.js",
"clear-platform": "node ./native/utils/clear-platform.js && node ./scripts/clear-file.js",
"update:native-external": "node ./native/utils/update-external.js",
Expand All @@ -44,7 +43,7 @@
"@pal/utils": "*",
"@cocos/box2d": "1.0.1",
"@cocos/cannon": "1.2.8",
"@cocos/ccbuild": "2.0.3-alpha.13",
"@cocos/ccbuild": "2.0.3-alpha.14",
"@cocos/dragonbones-js": "^1.0.1"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/build-engine/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"sourceMap": true,
"declaration": true,
"rootDir": "src",
"outDir": "lib"
"outDir": "lib",
"types": []
},
"exclude": [
"lib",
Expand Down
21 changes: 21 additions & 0 deletions packages/cc-ambient-types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "../../schemas/module-config.schema.json",
"name": "@types/cc-ambient-types",
"version": "1.0.0",
"description": "",
"scripts": {
"build": "node ./scripts/build-consts.js"
},
"license": "MIT",
"types": "./src/index.d.ts",
"exports": {
".": {
"node": "./src/index.d.ts",
"types": "./src/index.d.ts"
},
"./query": "./scripts/query.js"
},
"devDependencies": {
"@cocos/ccbuild": "*"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const { StatsQuery } = require('@cocos/build-engine');
const { StatsQuery } = require('@cocos/ccbuild');
const ps = require('path');
const fsExt = require('fs-extra');
const chalk = require('chalk').default;

const engineRoot = ps.join(__dirname, '../');
const targetConstFile = ps.join(engineRoot, `./@types/consts.d.ts`);
const engineRoot = ps.join(__dirname, '../../../');
const pkgRoot = ps.join(__dirname, '../');
const targetConstFile = ps.join(pkgRoot, `./lib/consts.d.ts`);

console.log(chalk.green(`\nGenerate consts.d.ts: ${targetConstFile}\n`));

Expand Down
14 changes: 14 additions & 0 deletions packages/cc-ambient-types/scripts/query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const ps = require('path');
const fs = require('fs');

function formatPath (path) {
return path.replace(/\\/g, '/');
}

exports.getDtsFiles = function () {
const indexFile = ps.join(__dirname, '../src/index.d.ts');
const indexContent = fs.readFileSync(indexFile, 'utf8');
const reg = /".*"/g;
const dtsFiles = indexContent.match(reg).map(relativePath => formatPath(ps.join(ps.dirname(indexFile), relativePath.slice(1, -1))));
return dtsFiles;
};
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions packages/cc-ambient-types/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint-disable @typescript-eslint/triple-slash-reference */
// default ambient types
/// <reference path="../lib/consts.d.ts"/>
/// <reference path="./editor-extends.d.ts"/>
/// <reference path="./globals.d.ts"/>
/// <reference path="./jsb.d.ts"/>
/// <reference path="./webGL.extras.d.ts"/>
/// <reference path="./webGL2.extras.d.ts"/>

// node_modules types
/// <reference path="../../../node_modules/@cocos/cannon/CANNON.d.ts"/>

// pal types
/// <reference path="./pal/audio.d.ts"/>
/// <reference path="./pal/input.d.ts"/>
/// <reference path="./pal/minigame.d.ts"/>
/// <reference path="./pal/pacer.d.ts"/>
/// <reference path="./pal/screen-adapter.d.ts"/>
/// <reference path="./pal/system-info.d.ts"/>
/// <reference path="./pal/wasm.d.ts"/>
/// <reference path="./pal/image.d.ts"/>

// external types
/// <reference path="../../../native/external/emscripten/external-wasm.d.ts"/>
/// <reference path="../../../native/external/emscripten/bullet/bullet.d.ts"/>
/// <reference path="../../../native/external/emscripten/physx/physx.d.ts"/>
/// <reference path="../../../native/external/emscripten/webgpu/webgpu.d.ts"/>
/// <reference path="../../../native/external/emscripten/spine/spine.d.ts"/>
/// <reference path="../../../native/external/emscripten/meshopt/meshopt_decoder.d.ts"/>
/// <reference path="../../../native/external/emscripten/box2d/box2d.d.ts"/>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ declare module 'pal/audio' {
* @param opts Load options.
* @returns The audio player.
*/
static load (url: string, opts?: import('pal/audio/type').AudioLoadOptions): Promise<AudioPlayer>;
static load (url: string, opts?: import('../../../../pal/audio/type').AudioLoadOptions): Promise<AudioPlayer>;

/**
* Asynchronously load a native audio for playing one shot.
Expand All @@ -59,7 +59,7 @@ declare module 'pal/audio' {
* @param opts Load options.
* @returns The native audio such as `HTMLAudioElement` or `AudioBuffer`.
*/
static loadNative (url: string, opts?: import('pal/audio/type').AudioLoadOptions): Promise<unknown>;
static loadNative (url: string, opts?: import('../../../../pal/audio/type').AudioLoadOptions): Promise<unknown>;

/**
* Asynchronously load an OneShotAudio instance.
Expand All @@ -68,7 +68,7 @@ declare module 'pal/audio' {
* @param opts Load options.
* @returns The OneShotAudio instance.
*/
static loadOneShotAudio (url: string, volume: number, opts?: import('pal/audio/type').AudioLoadOptions): Promise<OneShotAudio>;
static loadOneShotAudio (url: string, volume: number, opts?: import('../../../../pal/audio/type').AudioLoadOptions): Promise<OneShotAudio>;

/**
* Max audio channel count allowed on current platform.
Expand All @@ -86,13 +86,13 @@ declare module 'pal/audio' {
* The type of this player.
* For WEB platform, it can be `WEB_AUDIO` or `DOM_AUDIO`.
*/
get type (): import('pal/audio/type').AudioType;
get type (): import('../../../../pal/audio/type').AudioType;

/**
* The state of this player.
* The state would be restored to `INIT` when the audio finished its playing.
*/
get state (): import('pal/audio/type').AudioState;
get state (): import('../../../../pal/audio/type').AudioState;

/**
* Gets or sets whether if the playing audio should be looped.
Expand Down Expand Up @@ -126,7 +126,7 @@ declare module 'pal/audio' {
* Get pcm data view from specified channel.
* @param channelIndex The channel index. 0 is left channel, 1 is right channel.
*/
public getPCMData (channelIndex: number): import('pal/audio/type').AudioPCMDataView | undefined;
public getPCMData (channelIndex: number): import('../../../../pal/audio/type').AudioPCMDataView | undefined;

/**
* Asynchronously seeks the player's playing time onto specified location.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
declare module 'pal/image' {

export type ImageSource = import('pal/image/types').ImageSource;
export type IMemoryImageSource = import('pal/image/types').IMemoryImageSource;
export type PixelFormat = import('cocos/asset/assets/asset-enum').PixelFormat;
export type RawDataType = import('pal/image/types').RawDataType;
export type ImageSource = import('../../../../pal/image/types').ImageSource;
export type IMemoryImageSource = import('../../../../pal/image/types').IMemoryImageSource;
export type PixelFormat = import('../../../../cocos/asset/assets/asset-enum').PixelFormat;
export type RawDataType = import('../../../../pal/image/types').RawDataType;
export class ImageData {
constructor (source?: ImageSource | ArrayBufferView);
/**
Expand Down
File renamed without changes.
Loading

0 comments on commit 471fe46

Please sign in to comment.