Skip to content

Commit 1af2027

Browse files
committed
take deps from toolkit
1 parent 29a5ed0 commit 1af2027

File tree

11 files changed

+100
-574
lines changed

11 files changed

+100
-574
lines changed

package-lock.json

Lines changed: 1 addition & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
"test": "npm run test-08:00 && npm run test+08:00 && npm run test-local",
1717
"clean": "rimraf ./lib",
1818
"prebuild": "npm run clean",
19-
"build": "tsc -p ./tsconfig.json && tsc -p ./tsconfig.cjs.json && node ./scripts/generate-deep-package.js && node ./scripts/generate-root-declarations.js",
19+
"build": "tsc -p ./tsconfig.json && tsc -p ./tsconfig.cjs.json && node ./scripts/generate-deep-package.js",
2020
"postbuild": "cp package.json README.md LICENSE NOTICE lib",
21-
"prepare": "husky"
21+
"prepare": "husky",
22+
"postinstall": "node ./scripts/install-peer-dependency.js component-toolkit:selection-tree"
2223
},
2324
"type": "module",
2425
"main": "./cjs/index.js",
@@ -33,17 +34,10 @@
3334
"require": "./cjs/operations.js",
3435
"default": "./mjs/operations.js"
3536
},
36-
"./internal-do-not-use": {
37-
"require": "./cjs/internal-do-not-use.js",
38-
"default": "./mjs/internal-do-not-use.js"
39-
}
4037
},
4138
"files": [
4239
"cjs",
4340
"mjs",
44-
"index.d.ts",
45-
"operations.d.ts",
46-
"internal-do-not-use.d.ts",
4741
"package.json",
4842
"README.md",
4943
"LICENSE",

scripts/generate-root-declarations.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

scripts/install-peer-dependency.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env node
2+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
// Can be used in postinstall script like so:
6+
// "postinstall": "node ./scripts/install-peer-dependency.js collection-hooks:property-filter-token-groups"
7+
// where "collection-hooks" is the package to fetch and "property-filter-token-groups" is the branch name in GitHub.
8+
9+
import { execSync } from 'child_process';
10+
import process from 'node:process';
11+
import os from 'os';
12+
import path from 'path';
13+
14+
const getModules = packageName => {
15+
switch (packageName) {
16+
case 'components':
17+
return ['components', 'design-tokens'];
18+
case 'theming-core':
19+
return ['theming-build', 'theming-runtime'];
20+
default:
21+
return [packageName];
22+
}
23+
};
24+
25+
const getArtifactPath = moduleName => {
26+
switch (moduleName) {
27+
case 'components':
28+
return '/lib/components/*';
29+
case 'design-tokens':
30+
return '/lib/design-tokens/*';
31+
case 'board-components':
32+
return '/lib/components/*';
33+
case 'theming-build':
34+
return '/lib/node/*';
35+
case 'theming-runtime':
36+
return '/lib/browser/*';
37+
default:
38+
return '/lib/*';
39+
}
40+
};
41+
42+
const args = process.argv.slice(2);
43+
if (args.length < 1) {
44+
console.error('Usage: install-peer-dependency.js <package-name>:<target-branch>');
45+
process.exit(1);
46+
}
47+
const [packageName, targetBranch] = args[0].split(':');
48+
const targetRepository = `https://github.com/cloudscape-design/${packageName}.git`;
49+
const nodeModulesPath = path.join(process.cwd(), 'node_modules', '@cloudscape-design');
50+
const tempDir = path.join(os.tmpdir(), `temp-${packageName}`);
51+
52+
// Clone the repository and checkout the branch
53+
console.log(`Cloning ${packageName}:${targetBranch}...`);
54+
execCommand(`git clone ${targetRepository} ${tempDir}`);
55+
process.chdir(tempDir);
56+
execCommand(`git checkout ${targetBranch}`);
57+
58+
// Install dependencies and build
59+
console.log(`Installing dependencies and building ${packageName}...`);
60+
execCommand('npm install');
61+
execCommand('npm run build');
62+
63+
// Remove existing peer dependency in node_modules
64+
for (const moduleName of getModules(packageName)) {
65+
const modulePath = path.join(nodeModulesPath, moduleName);
66+
const artifactPath = getArtifactPath(moduleName);
67+
68+
console.log(`Removing existing ${moduleName} from node_modules...`, modulePath);
69+
execCommand(`rm -rf ${modulePath}`);
70+
71+
// Copy built peer dependency to node_modules
72+
console.log(`Copying built ${moduleName} to node_modules...`, modulePath, `${tempDir}${artifactPath}`);
73+
execCommand(`mkdir -p ${modulePath}`);
74+
execCommand(`cp -R ${tempDir}${artifactPath} ${modulePath}`);
75+
}
76+
77+
// Clean up
78+
console.log('Cleaning up...');
79+
execCommand(`rm -rf ${tempDir}`);
80+
81+
console.log(`${packageName} has been successfully installed from branch ${targetBranch}!`);
82+
83+
function execCommand(command, options = {}) {
84+
try {
85+
execSync(command, { stdio: 'inherit', ...options });
86+
} catch (error) {
87+
console.error(`Error executing command: ${command}`);
88+
console.error(`Error message: ${error.message}`);
89+
console.error(`Stdout: ${error.stdout && error.stdout.toString()}`);
90+
console.error(`Stderr: ${error.stderr && error.stderr.toString()}`);
91+
throw error;
92+
}
93+
}

0 commit comments

Comments
 (0)