From a01885a0070da86c9f6f9985ba2e0e91986827e3 Mon Sep 17 00:00:00 2001 From: richardo2016 Date: Fri, 10 Nov 2023 16:29:23 +0800 Subject: [PATCH] feat: upgrade compilation, deps, ci config. --- .github/workflows/run-ci.yml | 88 +++++++++++++++++++++++++++++ .github/workflows/set-env-vars.sh | 56 ++++++++++++++++++ .travis.yml | 70 ----------------------- .typifyrc.json | 5 -- @types/index.d.ts | 4 -- package.json | 24 ++++---- src/builtin-modules.ts | 26 +++++++-- src/index.ts | 12 +++- src/util/get-builtin-module-hash.ts | 4 +- src/util/is-builtin-module.ts | 2 +- tsconfig.json | 32 +++++++++++ 11 files changed, 222 insertions(+), 101 deletions(-) create mode 100644 .github/workflows/run-ci.yml create mode 100644 .github/workflows/set-env-vars.sh delete mode 100644 .travis.yml delete mode 100644 .typifyrc.json delete mode 100644 @types/index.d.ts create mode 100644 tsconfig.json diff --git a/.github/workflows/run-ci.yml b/.github/workflows/run-ci.yml new file mode 100644 index 0000000..c13ab27 --- /dev/null +++ b/.github/workflows/run-ci.yml @@ -0,0 +1,88 @@ +name: run ci for fibjs + +on: + push: + branches: + - 'ci/**' + - 'ci-**' + - 'releases/**' + - 'feat/**' + - 'bugfix/**' + - 'dev' + - 'master' + - 'test_ci' + tags: + - v*.*.* + - test_github_actions_* + pull_request: + branches: + - 'dev' + +jobs: + build: + runs-on: ${{ matrix.os }} + continue-on-error: true + strategy: + matrix: + os: [ubuntu-18.04, windows-2019, macos-10.15] + version: [0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0] + arch: [amd64, i386] + exclude: + - os: windows-2019 + arch: i386 + - os: macos-10.15 + arch: i386 + + steps: + - name: Check out Git repository + uses: actions/checkout@v2 + with: + submodules: 'recursive' + + - uses: actions/setup-node@v2 + with: + node-version: '14' + + - name: Set Env Variables + id: set-env-vars + shell: bash + run: | + bash .github/workflows/set-env-vars.sh + env: + ARCH: ${{ matrix.arch }} + OS: ${{ matrix.os }} + + - name: Install FIBJS + shell: bash + run: | + mkdir -p ./node_modules/.bin; + rm -rf ./node_modules/.bin/fibjs; + if [[ "$RUNNER_OS" == "Linux" ]]; then + curl -SL "https://github.com/fibjs/fibjs/releases/download/v${FIBJS_VERSION}/fibjs-v${FIBJS_VERSION}-${FIBJS_OS}-${FIBJS_ARCH}.xz" -o ./node_modules/.bin/fibjs.xz; + xz -d ./node_modules/.bin/fibjs.xz; + chmod a+x ./node_modules/.bin/fibjs; + elif [[ "$RUNNER_OS" == "macOS" ]]; then + curl -SL "https://github.com/fibjs/fibjs/releases/download/v${FIBJS_VERSION}/fibjs-v${FIBJS_VERSION}-${FIBJS_OS}-${FIBJS_ARCH}" -o ./node_modules/.bin/fibjs; + chmod a+x ./node_modules/.bin/fibjs; + else + curl -SL "https://github.com/fibjs/fibjs/releases/download/v${FIBJS_VERSION}/fibjs-v${FIBJS_VERSION}-${FIBJS_OS}-${FIBJS_ARCH}.exe" -o ./node_modules/.bin/fibjs.exe; + fi + env: + FIBJS_OS: ${{ steps.set-env-vars.outputs.FIBJS_OS }} + FIBJS_ARCH: ${{ steps.set-env-vars.outputs.FIBJS_ARCH }} + FIBJS_VERSION: ${{ matrix.version }} + + - name: Run CI + shell: bash + run: | + if [[ -f ".github/workflows/run-ci.sh" ]]; then + bash .github/workflows/run-ci.sh; + else + npm install; + npm run ci; + fi + env: + FIBJS_OS: ${{ steps.set-env-vars.outputs.FIBJS_OS }} + GIT_BRANCH: ${{ steps.set-env-vars.outputs.GIT_BRANCH }} + RELEASE_TAG: ${{ steps.set-env-vars.outputs.RELEASE_TAG }} + GIT_TAG: ${{ steps.set-env-vars.outputs.GIT_TAG }} diff --git a/.github/workflows/set-env-vars.sh b/.github/workflows/set-env-vars.sh new file mode 100644 index 0000000..9798ca8 --- /dev/null +++ b/.github/workflows/set-env-vars.sh @@ -0,0 +1,56 @@ +export GIT_BRANCH=${GITHUB_REF#refs/heads/} +echo "::set-output name=GIT_BRANCH::$GIT_BRANCH" +export GIT_TAG=$(git tag | grep $(git describe --tags HEAD)) +echo "::set-output name=GIT_TAG::$GIT_TAG" +export GIT_COMMIT_HEAD_MSG=$(git log --format=%b -1) +echo "::set-output name=GIT_COMMIT_HEAD_MSG::$GIT_COMMIT_HEAD_MSG" +export GIT_COMMIT_SHORTCUTS=$(git log --format=%h -1) +echo "::set-output name=GIT_COMMIT_SHORTCUTS::$GIT_COMMIT_SHORTCUTS" +export GIT_COMMIT_TIME=$(git show -s --format="%cd" --date=format:%Y%m%d%H%M%S HEAD) +echo "::set-output name=GIT_COMMIT_TIME::$GIT_COMMIT_TIME" + +if [[ "$GIT_TAG" =~ ^v?[012]\.[0-9]+\.[0-9]+$ ]]; then + export IS_GIT_TAG_MATCH_SEMVER="true" + echo "::set-output name=IS_GIT_TAG_MATCH_SEMVER::$IS_GIT_TAG_MATCH_SEMVER" +fi + +if [ -z "$GIT_TAG" ]; then + export RELEASE_TAG="$GIT_COMMIT_TIME-$GIT_COMMIT_SHORTCUTS"; +else + export RELEASE_TAG="$GIT_TAG"; +fi +if [ -z "$IS_GIT_TAG_MATCH_SEMVER" ]; then + SUFFIX=${GIT_BRANCH//\//'-'} + RELEASE_TAG="$RELEASE_TAG-$SUFFIX" +fi +echo "::set-output name=RELEASE_TAG::$RELEASE_TAG"; + +case "${RUNNER_OS}" in + Windows) + export FIBJS_OS=windows + ;; + macOS) + export FIBJS_OS=darwin + ;; + Linux) + export FIBJS_OS=linux + ;; + *) + echo "unsupported RUNNER_OS ${RUNNER_OS}"; + exit 1 + ;; +esac +echo "::set-output name=FIBJS_OS::$FIBJS_OS"; + +case "${ARCH}" in + i386) + export FIBJS_ARCH=x86 + ;; + amd64) + export FIBJS_ARCH=x64 + ;; + *) + export FIBJS_ARCH=$ARCH + ;; +esac +echo "::set-output name=FIBJS_ARCH::$FIBJS_ARCH"; diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e17ab8b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,70 +0,0 @@ -language: node_js -node_js: '6' -matrix: - include: - - os: linux - env: - - VERSION=0.21.0 - - os: linux - env: - - VERSION=0.22.0 - - os: linux - env: - - VERSION=0.23.0 - - os: linux - env: - - VERSION=0.24.0 - - os: linux - env: - - VERSION=0.25.0 - - os: linux - env: - - VERSION=0.26.0 - - os: linux - env: - - VERSION=0.26.1 - - os: osx - osx_image: xcode9 - env: - - VERSION=0.21.0 - - os: osx - osx_image: xcode9 - env: - - VERSION=0.22.0 - - os: osx - osx_image: xcode9 - env: - - VERSION=0.23.0 - - os: osx - osx_image: xcode9 - env: - - VERSION=0.24.0 - - os: osx - osx_image: xcode9 - env: - - VERSION=0.25.0 - - os: osx - osx_image: xcode9 - env: - - VERSION=0.26.0 - - os: osx - osx_image: xcode9 - env: - - VERSION=0.26.1 -before_install: - - OS=linux - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - rvm install ruby-2.4.0; - rvm --default use 2.4.0; - ruby -v; - brew update; - brew install xz; - OS=darwin; - fi -script: - - npm i - - mkdir -p ./node_modules/.bin - - curl -SL "https://github.com/fibjs/fibjs/releases/download/v${VERSION}/fibjs-v${VERSION}-${OS}-x64.xz" -o ./node_modules/.bin/fibjs.xz - - xz -d ./node_modules/.bin/fibjs.xz - - chmod a+x ./node_modules/.bin/fibjs - - npm run ci diff --git a/.typifyrc.json b/.typifyrc.json deleted file mode 100644 index 7a256f1..0000000 --- a/.typifyrc.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "target": "es6", - "module": "commonjs", - "noImplicitUseStrict": true -} \ No newline at end of file diff --git a/@types/index.d.ts b/@types/index.d.ts deleted file mode 100644 index a8002a4..0000000 --- a/@types/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module "@fibjs/builtin-modules" { - const moduleList: string[] - export = moduleList -} diff --git a/package.json b/package.json index 0ac5400..e75a5dd 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "builtin-modules of fibjs", "main": "./lib/index.js", "scripts": { - "build": "fib-typify src -c .typifyrc.json -o lib", + "build": "rimraf ./lib ./typings && ftsc ./src/* --outDir ./lib", "test": "fibjs test/index.js", "ci": "npm run build && npm run test", "prepublishOnly": "npm run build" @@ -24,20 +24,20 @@ }, "homepage": "https://github.com/fibjs-modules/builtin-modules#readme", "devDependencies": { - "@fibjs/ci": "^2.1.0", - "@types/fibjs": "^0.26.3", - "fib-typify": "^0.3.1" + "@fibjs/ci": "^2.6.0", + "@fibjs/types": "^0.36.1", + "fib-typify": "^0.11.5", + "rimraf": "^5.0.5" }, "ci": { - "type": "travis", + "type": "actions", "version": [ - "0.21.0", - "0.22.0", - "0.23.0", - "0.24.0", - "0.25.0", - "0.26.0", - "0.26.1" + "0.31.0", + "0.32.0", + "0.33.0", + "0.34.0", + "0.35.0", + "0.36.0" ] }, "engines": { diff --git a/src/builtin-modules.ts b/src/builtin-modules.ts index 63372f2..c26c2c9 100644 --- a/src/builtin-modules.ts +++ b/src/builtin-modules.ts @@ -1,3 +1,5 @@ +/// + import util = require('util') const builtInfo: any = util.buildInfo() @@ -13,14 +15,28 @@ const builtInModulesVersionMap = { "0.23.0": [ "zmq", "zlib", "zip", "xml", "ws", "vm", "uuid", "util", "url", "tty", "timers", "test", "string_decoder", /* "tls", */ "ssl", "querystring", "punycode", "profiler", "process", "path", "os", "net", "mq", "json", "io", "iconv", /* "https", */ "http", "hex", "hash", "gd", "fs", "events", "encoding", "dns", "dgram", "db", "crypto", "coroutine", "buffer", "bson", "base64vlq", "base64", "base32", "assert" ], "0.22.0": [ "zmq", "zlib", "zip", "xml", "ws", "vm", "uuid", "util", "url", "tty", "timers", "test", "string_decoder", /* "tls", */ "ssl", "querystring", "punycode", "profiler", "process", "path", "os", "net", "mq", "json", "io", "iconv", /* "https", */ "http", "hex", "hash", "gd", "fs", "events", "encoding", "dns", "dgram", "db", "crypto", "coroutine", "buffer", "bson", "base64vlq", "base64", "base32", "assert" ], "0.21.0": [ "zmq", "zlib", "zip", "xml", "ws", "vm", "uuid", "util", "url", "tty", "timers", "test", "string_decoder", /* "tls", */ "ssl", "querystring", "punycode", "profiler", "process", "path", "os", "net", "mq", "json", "io", "iconv", /* "https", */ "http", "hex", "hash", "gd", "fs", "events", "encoding", "dns", /* "dgram", */ "db", "crypto", "coroutine", "buffer", "bson", "base64vlq", "base64", "base32", "assert" ] +} as Record + +// since 0.37.0, builtInfo.fibjsBuiltins, builtInfo.builtins is available +let internalModuleNameList: string[] | null = null; + +if (Array.isArray(builtInfo.builtins) && builtInfo.builtins.length) { + internalModuleNameList = builtInfo.builtins +} else if (Array.isArray(builtInfo.fibjsBuiltins) && builtInfo.fibjsBuiltins.length) { + internalModuleNameList = builtInfo.fibjsBuiltins +} else if (Array.isArray(builtInfo.modules) && builtInfo.modules.length) { + internalModuleNameList = builtInfo.modules } -const internalModuleNameList = builtInfo.modules && builtInfo.modules.length ? builtInfo.modules : null +type ModuleList = string[] & { + default: ModuleList; +} -const moduleList = +const moduleList = ( internalModuleNameList ? internalModuleNameList : - (fibjsVersion && builtInModulesVersionMap[fibjsVersion] ? builtInModulesVersionMap[fibjsVersion] : builtInModulesVersionMap['default']); + (fibjsVersion && builtInModulesVersionMap[fibjsVersion] ? builtInModulesVersionMap[fibjsVersion] : builtInModulesVersionMap['default'])) as ModuleList; + +moduleList.default = moduleList -;(moduleList as any).default = moduleList -export = moduleList +export = moduleList; diff --git a/src/index.ts b/src/index.ts index 7b586a2..e9b1477 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,11 @@ -import builtInModules from './builtin-modules' +/// -export = builtInModules +import './util/get-builtin-module-hash'; +import './util/is-builtin-module'; + +import builtInModules = require('./builtin-modules') + +export = builtInModules; + +// export * from './util/get-builtin-module-hash'; +// export * from './util/is-builtin-module'; \ No newline at end of file diff --git a/src/util/get-builtin-module-hash.ts b/src/util/get-builtin-module-hash.ts index 2e1a817..d1699a6 100644 --- a/src/util/get-builtin-module-hash.ts +++ b/src/util/get-builtin-module-hash.ts @@ -1,7 +1,7 @@ -const builtInModules = require('../../') +import builtInModules from '../builtin-modules' export = function getBuiltInModuleHash () { - const hash = {} + const hash = {} as Record builtInModules.forEach(name => hash[name] = require(name)) return hash } diff --git a/src/util/is-builtin-module.ts b/src/util/is-builtin-module.ts index 15740a2..c6961a8 100644 --- a/src/util/is-builtin-module.ts +++ b/src/util/is-builtin-module.ts @@ -1,4 +1,4 @@ -const builtInModules = require('../../') +import builtInModules from '../builtin-modules' export = function isBuiltInModule (moduleName: string) { return builtInModules.includes(moduleName) diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..c54fff6 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,32 @@ +{ + "compilerOptions": { + "target": "es6", + "module": "commonjs", + "noImplicitAny": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "inlineSourceMap": false, + "allowJs": true, + "lib": [ + "es6", + "es2015", + "es2016" + ], + "declaration": true, + "declarationDir": "typings", + "types": [ + "@fibjs/types" + ], + "typeRoots": [ + "typings/index.d.ts" + ] + }, + "include": [ + "src/**/*", + "src/util/is-builtin-module.ts" + ], + "exclude": [ + "src/**/*.js", + "test/**/*" + ] +}