Reputation: 1164
I have a small Cloud Build pipeline with a build process to publish a private npm package to Artifact Registry.
My problem is that upon npm publish
, the dist folder is systematically removed from the package.
I have ensured that:
.npmignore
file present in my repo that supersedes the .gitignore
file and does not list dist
files
entry in my package.json
that references the dist
folder and its content (though that is not strictly required since I have a .npmignore
--no-git-tag-version
to my publish command as per this discussion.Things to note:
-w
flagdist
folder.My yaml file:
steps:
- name: node:16
entrypoint: npm
args: ["run", "artifactregistry-login"]
- name: node:16
entrypoint: npm
args: ["install"]
- name: node:16
entrypoint: npm
args:
["-w", "@myapp/config", "version", "0.0.1${_PRE_ID_STRING}.$COMMIT_SHA"]
- name: node:16
dir: "packages/config"
entrypoint: npm
args: ["run", "build"]
- name: "gcr.io/cloud-builders/gcloud"
dir: "packages/config"
entrypoint: bash
args:
- "-c"
- |
find . -type f ! -name "package.json" -delete
rm -rf src
rm -rf tsconfig
# Quick check to see if dist is there at this point and it is.
- name: "gcr.io/cloud-builders/gcloud"
dir: "packages/config"
entrypoint: bash
args:
- "-c"
- |
echo "---before publish---"
ls -lia
cd ./dist
- name: node:16
entrypoint: npm
args: ["-w", "@myapp/config", "publish", "--no-git-tag-version"]
substitutions:
_PRE_ID_STRING: ""
options:
substitution_option: "ALLOW_LOOSE"
timeout: "1000s"
And the package.json (with a desperate attempt to capture my dist contents with an awful glob pattern):
{
"name": "@myapp/config",
"version": "xxxx",
"license": "MIT",
"scripts": {
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.esm.json",
"build": "npm run build:cjs && npm run build:esm"
},
"exports": {
".": {
"import": "./dist/esm/src/index.js",
"require": "./dist/cjs/src/index.js"
},
},
"types": "./dist/cjs/src/index.d.ts",
"publishConfig": {
"access": "restricted",
"registry": "https://europe-west2-npm.pkg.dev"
},
"files": [
"dist/**/*",
"./dist/**/*",
"./dist/**/**/*",
"./dist/**/**/**/*",
"./dist/**/**/*",
"./dist/**/**/**/*",
"dist/**/*",
"dist/**/**/*",
"dist/**/**/**/*",
"dist/**/**/*",
"dist/**/**/**/*"
]
}
Any idea would be massively appreciated.
Thanks,
Upvotes: 0
Views: 235
Reputation: 1620
I encountered a similar issue previously when I overlooked running the build command.
Considering you're encountering the same problem, it's possible that the absence of a 'dist' folder might be due to not building the package beforehand. Perhaps you've mistakenly committed an outdated 'dist' folder?
To address this, you have a couple of options:
"scripts": {
"prepack": "npm run build"
}
This script will automatically execute the build command before the package will be published.
Upvotes: 0