diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 500acaf..a47bd7a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,6 +14,6 @@ jobs: - run: npm ci - run: npm run build:dist - run: npm test - - run: npm publish --access public + - run: npm run dist env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index dbb23c2..2b1e3e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # changelog -## 0.0.1 -**Date**: 2023-TODO +## 0.1.1 +**Date**: 2023-12-12 + +* Library and built script files are no longer in the `dist` folder, so you can remove `/dist` from import/script paths. + +## 0.1.0 +**Date**: 2023-12-08 Initial release. diff --git a/license-checker-config.json b/license-checker-config.json index 8adb187..800e3a5 100644 --- a/license-checker-config.json +++ b/license-checker-config.json @@ -24,6 +24,7 @@ "build/", "node_modules/", "temp/", + ".github/", "**/*.html", "**/*.md", diff --git a/package-lock.json b/package-lock.json index 42c3b09..8400972 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@friendlycaptcha/sdk", - "version": "0.1.0", + "version": "0.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@friendlycaptcha/sdk", - "version": "0.1.0", + "version": "0.1.1", "license": "MPL-2.0", "devDependencies": { "@ava/typescript": "^4.1.0", diff --git a/package.json b/package.json index f48f7fe..1045be7 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,12 @@ { "name": "@friendlycaptcha/sdk", - "version": "0.1.0", + "version": "0.1.1", "description": "In-browser SDK for Friendly Captcha v2 (currently in preview only)", "main": "dist/sdk.js", "type": "module", + "private": true, "scripts": { + "clean": "rm -rf dist build temp", "build": "./build.sh", "build:tsc": "tsc", "build:dist": "npm run build && npm run build:tsc && npm run build:dts && cp -r build/tsc/src/ dist/src && npm run build:apiextractor && npm run build:docs", @@ -15,7 +17,9 @@ "test": "ava test/**/*.ts --timeout=1m", "api-extractor": "api-extractor", "license-check-and-add": "license-check-and-add", - "fmt": "prettier src/**/*.ts test/**/*.ts package.json babel.config.cjs --write" + "fmt": "prettier src/**/*.ts test/**/*.ts package.json babel.config.cjs --write", + "dist": "npm run clean && npm run build:dist && node prepublish.mjs && cd dist && npm publish", + "prepublishOnly": "echo \"Run npm run dist to build the package and publish it\" && exit 1" }, "author": "Friendly Captcha GmbH", "license": "MPL-2.0", diff --git a/prepublish.mjs b/prepublish.mjs new file mode 100644 index 0000000..1463556 --- /dev/null +++ b/prepublish.mjs @@ -0,0 +1,34 @@ +/*! + * Copyright (c) Friendly Captcha GmbH 2023. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ +import fs from "fs"; +import filepath from "path"; + +// This script is run before publishing to npm, it copies some files into the dist folder and copies a slimmed down version of package.json +// into that folder too, along with some readme files. This is so that we can only publish the contents of the dist folder to npm, that way +// we don't have `/dist/` in any import paths. + +(() => { + const source = fs.readFileSync("package.json").toString("utf-8"); + const pkg = JSON.parse(source); + delete pkg.scripts; + delete pkg.devDependencies; + delete pkg.files; + delete pkg.ava; + delete pkg.private; + if (pkg.main.startsWith("dist/")) { + pkg.main = pkg.main.slice(5); + } + + const outFolder = "dist"; + + for (const file of ["LICENSE.md", "README.md", "CHANGELOG.md"]) { + fs.copyFileSync(file, filepath.join(outFolder, file)); + } + + fs.writeFileSync(filepath.join(outFolder, "/package.json"), Buffer.from(JSON.stringify(pkg, null, 2), "utf-8")); + fs.writeFileSync(filepath.join(outFolder, "/version.txt"), Buffer.from(pkg.version, "utf-8")); // Useful for CI/CD tagging of version. +})();