Skip to content

Commit 0108ede

Browse files
committed
fix(angular): replace workspace version before release
- Angular-Slickgrid is a little special since it has its own copy of dist/package.json copied before Lerna has chance to replace its `workspace:` protocol causing invalid published package
1 parent 376b066 commit 0108ede

5 files changed

Lines changed: 104 additions & 15 deletions

File tree

.github/workflows/publish-npm-latest.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ jobs:
106106
pnpm whoami
107107
pnpm exec ${{ env.LERNA_VERSION_QUERY }}
108108
109+
- name: replace Angular-Slickgrid "workspace:"
110+
run: pnpm replace-workspace
111+
109112
- name: OTP
110113
if: ${{ inputs.dryrun != true }}
111114
uses: step-security/wait-for-secrets@v1

frameworks/angular-slickgrid/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"angular:preview": "vite preview --outDir=website --port=4300",
3636
"prebuild": "pnpm lint",
3737
"build": "pnpm packagr",
38-
"postbuild": "npm-run-all copy:i18n",
38+
"postbuild": "pnpm run copy:i18n && pnpm run replace-workspace",
3939
"packagr": "ng-packagr -p ng-package.json -c tsconfig.json",
4040
"copy:i18n": "copyfiles src/assets/i18n/*.json dist/i18n --flat --stat",
4141
"delete:dist": "rimraf dist",
@@ -44,6 +44,7 @@
4444
"lint:fix": "eslint --fix .",
4545
"pack-tarball": "npm pack",
4646
"pack-lib": "npm pack ./dist",
47+
"replace-workspace": "node ./scripts/replace-workspace.mjs",
4748
"test": "ng test --watch",
4849
"test:coverage": "vitest --no-watch --coverage"
4950
},
@@ -57,8 +58,9 @@
5758
"@slickgrid-universal/row-detail-view-plugin": "workspace:*",
5859
"@slickgrid-universal/rxjs-observable": "workspace:*",
5960
"@slickgrid-universal/utils": "workspace:*",
60-
"dequal": "catalog:",
61-
"rxjs": "catalog:"
61+
"dequal": "^2.0.3",
62+
"rxjs": "^7.8.2",
63+
"tslib": "^2.3.0"
6264
},
6365
"peerDependencies": {
6466
"@angular/core": ">=19.0.0"
@@ -118,13 +120,11 @@
118120
"native-copyfiles": "catalog:",
119121
"ng-packagr": "^19.2.2",
120122
"ngx-bootstrap": "^19.0.2",
121-
"npm-run-all2": "catalog:",
122123
"rimraf": "^6.0.1",
123124
"rxjs": "catalog:",
124125
"sass": "catalog:",
125126
"sortablejs": "catalog:",
126127
"ts-node": "^10.9.2",
127-
"tslib": "catalog:",
128128
"typescript": "~5.8.3",
129129
"typescript-eslint": "^8.32.1",
130130
"vite": "catalog:",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Copy some fs-extra util implementations
3+
* https://github.com/jprichardson/node-fs-extra
4+
*/
5+
6+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
7+
import { dirname } from 'node:path';
8+
9+
export function outputFileSync(file, ...args) {
10+
const dir = dirname(file);
11+
if (!existsSync(dir)) {
12+
mkdirSync(dir, { recursive: true });
13+
}
14+
15+
writeFileSync(file, ...args);
16+
}
17+
18+
export function readJSONSync(file, options = {}) {
19+
if (typeof options === 'string') {
20+
options = { encoding: options };
21+
}
22+
23+
const shouldThrow = 'throws' in options ? options.throws : true;
24+
25+
try {
26+
let content = readFileSync(file, options);
27+
content = stripBom(content);
28+
return JSON.parse(content, options.reviver);
29+
} catch (err) {
30+
if (shouldThrow) {
31+
err.message = `${file}: ${err.message}`;
32+
throw err;
33+
} else {
34+
return null;
35+
}
36+
}
37+
}
38+
39+
export function stringify(obj, { EOL = '\n', finalEOL = true, replacer = null, spaces } = {}) {
40+
const EOF = finalEOL ? EOL : '';
41+
const str = JSON.stringify(obj, replacer, spaces);
42+
43+
return str.replace(/\n/g, EOL) + EOF;
44+
}
45+
46+
export function stripBom(content) {
47+
// we do this because JSON.parse would convert it to a utf8 string if encoding wasn't specified
48+
if (Buffer.isBuffer(content)) {
49+
content = content.toString('utf8');
50+
}
51+
return content.replace(/^\uFEFF/, '');
52+
}
53+
54+
export function writeJsonSync(file, obj, options = {}) {
55+
const str = stringify(obj, options);
56+
// not sure if fs.writeFileSync returns anything, but just in case
57+
return writeFileSync(file, str, options);
58+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { dirname as pDirname, join as pJoin, resolve as pResolve } from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
4+
import { readJSONSync, writeJsonSync } from './fs-utils.mjs';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = pDirname(__filename);
8+
const projectRootPath = pJoin(__dirname, '../');
9+
10+
/**
11+
* Main entry, this script will replace all workspace protocol
12+
* with current version from "package.json" root into "dist/package.json"
13+
*/
14+
(async function main() {
15+
const rootPkg = readJSONSync(pJoin(projectRootPath, 'package.json'));
16+
const distPkg = readJSONSync(pJoin(projectRootPath, 'dist', 'package.json'));
17+
const currentVersion = rootPkg.version;
18+
19+
// replace all workspace protocol with current version from "package.json" root into "dist/package.json"
20+
console.log('-------------------------------------------------------------------------------------');
21+
console.log(`- Angular-Slickgrid, replace all "workspace:*" with "${currentVersion}" in "dist/package.json"`);
22+
for (let [depName, depVersion] of Object.entries(distPkg.dependencies)) {
23+
if (depVersion.startsWith('workspace:*')) {
24+
distPkg.dependencies[depName] = currentVersion;
25+
}
26+
}
27+
writeJsonSync(pResolve(projectRootPath, 'dist', 'package.json'), distPkg, { spaces: 2 });
28+
console.log('-------------------------------------------------------------------------------------\n');
29+
30+
process.exit();
31+
})();

pnpm-lock.yaml

Lines changed: 7 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)