diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0bb26be7..10e9ca84 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,4 +35,3 @@ jobs: - run: npm ci - run: npm run test - run: npm run test:node - - run: npm run test:pack diff --git a/.husky/pre-commit b/.husky/pre-commit index 041c660c..72c4429b 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1 @@ -npx --no-install lint-staged +npm test diff --git a/examples/benchmark/package-lock.json b/examples/benchmark/package-lock.json index 2af4264e..661709e8 100644 --- a/examples/benchmark/package-lock.json +++ b/examples/benchmark/package-lock.json @@ -8,51 +8,12 @@ "name": "uuid-benchmark", "version": "0.0.0", "dependencies": { - "uuid": "file:../../.local/uuid" + "uuid": "file:../../.build/uuid.tgz" }, "devDependencies": { "benchmark": "^2.1.4" } }, - "../../.local/uuid": { - "version": "10.0.0", - "funding": [ - "https://github.com/sponsors/broofa", - "https://github.com/sponsors/ctavan" - ], - "license": "MIT", - "bin": { - "uuid": "dist/esm/bin/uuid" - }, - "devDependencies": { - "@babel/eslint-parser": "7.24.8", - "@commitlint/cli": "19.3.0", - "@commitlint/config-conventional": "19.2.2", - "@eslint/js": "9.7.0", - "@types/eslint__js": "8.42.3", - "@wdio/browserstack-service": "8.39.1", - "@wdio/cli": "8.39.1", - "@wdio/jasmine-framework": "8.39.1", - "@wdio/local-runner": "8.39.1", - "@wdio/spec-reporter": "8.39.0", - "@wdio/static-server-service": "8.39.0", - "bundlewatch": "0.3.3", - "eslint": "9.7.0", - "eslint-config-prettier": "9.1.0", - "eslint-plugin-prettier": "5.2.1", - "globals": "15.8.0", - "husky": "9.1.1", - "jest": "29.7.0", - "lint-staged": "15.2.7", - "neostandard": "0.11.1", - "npm-run-all": "4.1.5", - "prettier": "3.3.3", - "runmd": "1.3.9", - "standard-version": "9.5.0", - "typescript": "5.5.3", - "typescript-eslint": "8.0.0-alpha.30" - } - }, "node_modules/benchmark": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/benchmark/-/benchmark-2.1.4.tgz", @@ -76,8 +37,17 @@ "dev": true }, "node_modules/uuid": { - "resolved": "../../.local/uuid", - "link": true + "version": "11.0.4", + "resolved": "file:../../.build/uuid.tgz", + "integrity": "sha512-z0G1Omuq4HgW+Ws4oA2974TU1nlh2QCaRUwGa67LaFYiFY6YhX2oecU1b2hIj40C5P8NF9hNkI1XCvw4bSF/nw==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/esm/bin/uuid" + } } }, "dependencies": { @@ -104,35 +74,8 @@ "dev": true }, "uuid": { - "version": "file:../../.local/uuid", - "requires": { - "@babel/eslint-parser": "7.24.8", - "@commitlint/cli": "19.3.0", - "@commitlint/config-conventional": "19.2.2", - "@eslint/js": "9.7.0", - "@types/eslint__js": "8.42.3", - "@wdio/browserstack-service": "8.39.1", - "@wdio/cli": "8.39.1", - "@wdio/jasmine-framework": "8.39.1", - "@wdio/local-runner": "8.39.1", - "@wdio/spec-reporter": "8.39.0", - "@wdio/static-server-service": "8.39.0", - "bundlewatch": "0.3.3", - "eslint": "9.7.0", - "eslint-config-prettier": "9.1.0", - "eslint-plugin-prettier": "5.2.1", - "globals": "15.8.0", - "husky": "9.1.1", - "jest": "29.7.0", - "lint-staged": "15.2.7", - "neostandard": "0.11.1", - "npm-run-all": "4.1.5", - "prettier": "3.3.3", - "runmd": "1.3.9", - "standard-version": "9.5.0", - "typescript": "5.5.3", - "typescript-eslint": "8.0.0-alpha.30" - } + "version": "file:../../.build/uuid.tgz", + "integrity": "sha512-z0G1Omuq4HgW+Ws4oA2974TU1nlh2QCaRUwGa67LaFYiFY6YhX2oecU1b2hIj40C5P8NF9hNkI1XCvw4bSF/nw==" } } } diff --git a/examples/benchmark/package.json b/examples/benchmark/package.json index 9caefc33..c30b8be5 100644 --- a/examples/benchmark/package.json +++ b/examples/benchmark/package.json @@ -5,6 +5,7 @@ "scripts": { "build": "true", "start": "npm run build && npx http-server . -o", + "pretest": "HUSKY=0 npm install", "test": "node node.js" }, "dependencies": { diff --git a/examples/browser-rollup/package.json b/examples/browser-rollup/package.json index 929c8a42..72e1298b 100644 --- a/examples/browser-rollup/package.json +++ b/examples/browser-rollup/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "private": true, "scripts": { - "build": "rm -rf dist && rollup -c", + "build": "npm install && rm -rf dist && rollup -c", "start": "npm run build && npx http-server . -o" }, "dependencies": { diff --git a/examples/browser-webpack/package.json b/examples/browser-webpack/package.json index b3e6b355..1983c364 100644 --- a/examples/browser-webpack/package.json +++ b/examples/browser-webpack/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "private": true, "scripts": { - "build": "rm -rf dist && webpack", + "build": "npm install && rm -rf dist && webpack", "start": "npm run build && npx http-server . -o" }, "dependencies": { diff --git a/examples/node-commonjs/package.json b/examples/node-commonjs/package.json index af1ca525..20c2bfc7 100644 --- a/examples/node-commonjs/package.json +++ b/examples/node-commonjs/package.json @@ -3,6 +3,7 @@ "version": "0.0.0", "private": true, "scripts": { + "pretest": "npm install", "test": "node example.js" }, "dependencies": { diff --git a/examples/node-esmodules/package.json b/examples/node-esmodules/package.json index 8d8b079b..cee6c45b 100644 --- a/examples/node-esmodules/package.json +++ b/examples/node-esmodules/package.json @@ -5,6 +5,7 @@ "scripts": { "test:package": "( node --version | grep -vq 'v16' ) || ( node --experimental-json-modules package.mjs )", "test:example": "node example.mjs", + "pretest": "npm install", "test": "npm-run-all test:*" }, "dependencies": { diff --git a/examples/node-jest/package.json b/examples/node-jest/package.json index 6a50ba77..832014c5 100644 --- a/examples/node-jest/package.json +++ b/examples/node-jest/package.json @@ -3,6 +3,7 @@ "version": "0.0.0", "private": true, "scripts": { + "pretest": "npm install", "test": "jest" }, "dependencies": { diff --git a/examples/node-webpack/package.json b/examples/node-webpack/package.json index 786d8ae9..139bbda9 100644 --- a/examples/node-webpack/package.json +++ b/examples/node-webpack/package.json @@ -4,6 +4,7 @@ "private": true, "scripts": { "build": "rm -rf dist && webpack", + "pretest": "npm install", "test": "npm run build && node dist/v1.js && node dist/v4.js && node dist/v7.js && node dist/all.js" }, "dependencies": { diff --git a/package.json b/package.json index a7461c07..292eea69 100644 --- a/package.json +++ b/package.json @@ -87,26 +87,26 @@ "docs": "npm run build && npx runmd --output=README.md README_js.md", "eslint:check": "eslint src/ test/ examples/ *.[jt]s", "eslint:fix": "eslint --fix src/ test/ examples/ *.[jt]s", - "examples:browser:rollup:build": "cd examples/browser-rollup && npm install && npm run build", - "examples:browser:webpack:build": "cd examples/browser-webpack && npm install && npm run build", - "examples:node:commonjs:test": "cd examples/node-commonjs && npm install && npm test", - "examples:node:esmodules:test": "cd examples/node-esmodules && npm install && npm test", - "examples:node:jest:test": "cd examples/node-jest && npm install && npm test", + "examples:browser:rollup:build": "cd examples/browser-rollup && npm run build", + "examples:browser:webpack:build": "cd examples/browser-webpack && npm run build", + "examples:node:commonjs:test": "cd examples/node-commonjs && npm test", + "examples:node:esmodules:test": "cd examples/node-esmodules && npm test", + "examples:node:jest:test": "cd examples/node-jest && npm test", "lint": "npm run eslint:check && npm run prettier:check", "md": "runmd --watch --output=README.md README_js.md", - "prepack": "npm run build", + "prepack": "npm run build -- --no-pack", "prepare": "husky", + "prepublishOnly": "npm run build", "pretest:benchmark": "npm run build", - "pretest:browser": "./scripts/iodd && npm run build && npm-run-all --parallel examples:browser:**", + "pretest:browser": "./scripts/iodd && npm run build && npm-run-all examples:browser:**", "pretest:node": "npm run build", "pretest": "npm run build", "prettier:check": "prettier --check .", "prettier:fix": "prettier --write .", "release": "standard-version --no-verify", - "test:benchmark": "cd examples/benchmark && HUSKY=0 npm install && npm test", + "test:benchmark": "cd examples/benchmark && npm test", "test:browser": "wdio run ./wdio.conf.js", - "test:node": "npm-run-all --parallel examples:node:**", - "test:pack": "./scripts/testpack.sh", + "test:node": "npm-run-all examples:node:**", "test:watch": "node --test --enable-source-maps --watch dist/esm/test/*.js", "test": "node --test --enable-source-maps dist/esm/test/*.js" }, diff --git a/scripts/build.sh b/scripts/build.sh index 9d61407f..1d9657b8 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -20,33 +20,29 @@ DIST_DIR="$ROOT/dist" rm -rf "$DIST_DIR" mkdir -p "$DIST_DIR" -# Prep build products dir (where we stick npm tarballs) -BUILD_DIR="$ROOT/.build" -rm -rf "$BUILD_DIR" -mkdir -p "$BUILD_DIR" - # Build each module type for MODULE_TYPE in esm cjs; do echo "Building ${MODULE_TYPE}" - MODULE_DIST_DIR="$DIST_DIR/${MODULE_TYPE}" - BROWSER_DIR="$DIST_DIR/${MODULE_TYPE}-browser" + NODE_DIST_DIR="$DIST_DIR/${MODULE_TYPE}" + BROWSER_DIST_DIR="$DIST_DIR/${MODULE_TYPE}-browser" tsc -p tsconfig.${MODULE_TYPE}.json # Clone files for browser builds - cp -pr ${MODULE_DIST_DIR} ${BROWSER_DIR} + cp -pr ${NODE_DIST_DIR} ${BROWSER_DIST_DIR} # Remove browser files from non-browser builds - for FILE in ${MODULE_DIST_DIR}/*-browser*;do + for FILE in ${NODE_DIST_DIR}/*-browser*;do rm -f $FILE done # Move browser files into place for browser builds ( - # Temporarily cd into BROWSER_DIR to avoid having to deal with "-browser" - # appearing in both the dir name and file name of FILE's full path - cd ${BROWSER_DIR} + # Temporarily cd into BROWSER_DIST_DIR to avoid having to deal with + # "-browser" appearing in both the dir name and file name of FILE's full + # path + cd ${BROWSER_DIST_DIR} for FILE in *-browser*;do mv $FILE ${FILE/-browser/} @@ -56,17 +52,24 @@ for MODULE_TYPE in esm cjs; do # esm/cjs-specific logic if [ "$MODULE_TYPE" = "esm" ]; then # ESM: copy bin files to dist - cp -pr "$DIST_DIR/../src/bin" "$MODULE_DIST_DIR" + cp -pr "$DIST_DIR/../src/bin" "$NODE_DIST_DIR" else # CJS: Add package.json that specifies type: commonjs - echo "{\"type\":\"commonjs\"}" > "$MODULE_DIST_DIR/package.json" - echo "{\"type\":\"commonjs\"}" > "$BROWSER_DIR/package.json" + echo "{\"type\":\"commonjs\"}" > "$NODE_DIST_DIR/package.json" + echo "{\"type\":\"commonjs\"}" > "$BROWSER_DIST_DIR/package.json" fi done -# Create tarball for local installation (in tests and examples) -echo "Packing tarball" -npm pack --ignore-scripts --pack-destination "$BUILD_DIR" > /dev/null 2>&1 -mv $BUILD_DIR/*.tgz $BUILD_DIR/uuid.tgz +if [ "${1-}" != "--no-pack" ]; then + # Prep tarball dir + BUILD_DIR="$ROOT/.build" + mkdir -p "$BUILD_DIR" + rm -rf "$BUILD_DIR/uuid-*.tgz" + + # Create tarball for local installation (in tests and examples) + echo "Packing tarball" + npm pack --pack-destination "$BUILD_DIR" > /dev/null 2>&1 + mv $BUILD_DIR/uuid-*.tgz $BUILD_DIR/uuid.tgz +fi echo "-- fin --" \ No newline at end of file diff --git a/scripts/testpack.sh b/scripts/testpack.sh deleted file mode 100755 index 9db00a99..00000000 --- a/scripts/testpack.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -eu - -# cd to the root dir -ROOT="$(pwd)/$(dirname "$0")/.." -cd "$ROOT" || exit 1 - -TEST_DIR=$(mktemp -d) - -mkdir -p ${TEST_DIR} - -trap 'rm -rf $TEST_DIR' EXIT - -# Create package tarball -npm pack --pack-destination=${TEST_DIR} - -# Set up a test project in the test directory -pushd ${TEST_DIR} -npm init -y -cp ${ROOT}/examples/node-commonjs/example.js commonjs.js -cp ${ROOT}/examples/node-esmodules/example.mjs esmodules.mjs -cp ${ROOT}/examples/node-esmodules/package.mjs esmodules-package.mjs - -# Install the tarball -npm install uuid*.tgz - -# Verify scripts that depend on package work -node commonjs.js -node esmodules.mjs - -# Support for json esm imports requires import assertions starting in Node.js v16.14.0 which were -# not supported in earlier versions. Therefore we restrict the ESM test to more recent versions of -# Node.js: -( node --version | grep -vq 'v16' ) || ( node --experimental-json-modules esmodules-package.mjs )