@taiga-ui/syncer 0.178.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @taiga-ui/syncer
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const tslib_1 = require("tslib");
5
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
6
+ const sync_versions_1 = require("./sync-versions");
7
+ const packageJson = require(node_path_1.default.resolve(process.cwd(), './package.json'));
8
+ const syncerOptions = packageJson?.syncer ?? null;
9
+ if (syncerOptions) {
10
+ (0, sync_versions_1.tuiSyncVersions)({
11
+ newVersion: packageJson.version,
12
+ includePaths: syncerOptions.includePaths,
13
+ matchPackageNames: syncerOptions.matchPackageNames,
14
+ ignorePackageNames: syncerOptions.ignorePackageNames,
15
+ });
16
+ }
17
+ else {
18
+ throw new Error(`Syncer options not found: ${JSON.stringify(packageJson)}`);
19
+ }
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tuiSyncVersions = tuiSyncVersions;
4
+ exports.tuiBumpDeps = tuiBumpDeps;
5
+ exports.tuiIsMatchedPackageName = tuiIsMatchedPackageName;
6
+ exports.tuiUpdatePackageJsonStructure = tuiUpdatePackageJsonStructure;
7
+ const node_fs_1 = require("node:fs");
8
+ const glob_1 = require("glob");
9
+ const INDENTATION = 4;
10
+ function tuiSyncVersions(options) {
11
+ const { includePaths, newVersion, ignorePackageNames, matchPackageNames } = options;
12
+ const patterns = includePaths.map((pattern) => pattern.endsWith('.json')
13
+ ? pattern
14
+ : `${pattern}/**/*(package.json|package-lock.json)`);
15
+ const files = patterns
16
+ .map((pattern) => glob_1.glob.sync(pattern, { ignore: '**/node_modules/**' }))
17
+ .flatMap((files) => files)
18
+ .filter((file) => !file.includes('node_modules'));
19
+ for (const file of files) {
20
+ const originalJSON = JSON.stringify(JSON.parse((0, node_fs_1.readFileSync)(file).toString()), null, INDENTATION);
21
+ const packageJson = JSON.parse(originalJSON);
22
+ const prevVersion = packageJson.version;
23
+ if (!prevVersion) {
24
+ continue;
25
+ }
26
+ tuiUpdatePackageJsonStructure({
27
+ isPackageLockFile: file.endsWith('-lock.json'),
28
+ packageJson,
29
+ prevVersion,
30
+ newVersion,
31
+ ignorePackageNames,
32
+ matchPackageNames,
33
+ });
34
+ const updatedJSON = JSON.stringify(packageJson, null, 4);
35
+ if (originalJSON !== updatedJSON) {
36
+ (0, node_fs_1.writeFileSync)(file, `${updatedJSON}\n`);
37
+ console.info(`[synchronized]: ${file}`);
38
+ }
39
+ else {
40
+ console.info(`[no changes]: ${file}`);
41
+ }
42
+ }
43
+ }
44
+ function tuiBumpDeps(options) {
45
+ const { deps, prevVersion, newVersion, isPeerDependency, ignorePackageNames, matchPackageNames, } = options;
46
+ Object.keys(deps)
47
+ .filter((key) => tuiIsMatchedPackageName({ name: key, ignorePackageNames, matchPackageNames }))
48
+ .forEach((key) => {
49
+ if (typeof deps[key] === 'string') {
50
+ deps[key] = isPeerDependency
51
+ ? deps[key]?.replace(prevVersion, newVersion)
52
+ : `^${newVersion}`;
53
+ }
54
+ else if (deps[key]?.hasOwnProperty('requires')) {
55
+ tuiBumpDeps({
56
+ deps: deps[key]?.requires ??
57
+ {},
58
+ isPeerDependency,
59
+ ignorePackageNames,
60
+ prevVersion,
61
+ newVersion,
62
+ matchPackageNames,
63
+ });
64
+ }
65
+ });
66
+ }
67
+ function tuiIsMatchedPackageName(options) {
68
+ const { name, ignorePackageNames, matchPackageNames } = options;
69
+ if (name && ignorePackageNames.includes(name)) {
70
+ return false;
71
+ }
72
+ return !!matchPackageNames.find((match) => !!name?.match(new RegExp(match)));
73
+ }
74
+ function tuiUpdatePackageJsonStructure({ packageJson, isPackageLockFile, ignorePackageNames, prevVersion, newVersion, matchPackageNames, }) {
75
+ const { name, dependencies, peerDependencies, devDependencies, packages } = packageJson;
76
+ if (typeof name === 'string' &&
77
+ tuiIsMatchedPackageName({ name, ignorePackageNames, matchPackageNames })) {
78
+ if ('version' in packageJson && typeof packageJson['version'] === 'string') {
79
+ packageJson['version'] = newVersion;
80
+ }
81
+ }
82
+ if (isObject(dependencies)) {
83
+ tuiBumpDeps({
84
+ deps: dependencies,
85
+ prevVersion,
86
+ newVersion,
87
+ matchPackageNames,
88
+ ignorePackageNames,
89
+ });
90
+ }
91
+ if (isObject(peerDependencies)) {
92
+ tuiBumpDeps({
93
+ deps: peerDependencies,
94
+ prevVersion,
95
+ newVersion,
96
+ isPeerDependency: true,
97
+ matchPackageNames,
98
+ ignorePackageNames,
99
+ });
100
+ }
101
+ if (isObject(devDependencies)) {
102
+ tuiBumpDeps({
103
+ deps: devDependencies,
104
+ prevVersion,
105
+ newVersion,
106
+ ignorePackageNames,
107
+ matchPackageNames,
108
+ });
109
+ }
110
+ if (isPackageLockFile && isObject(packages)) {
111
+ for (const packageLockJson of Object.values(packages)) {
112
+ if (!tuiIsMatchedPackageName({
113
+ name: packageLockJson?.name,
114
+ ignorePackageNames,
115
+ matchPackageNames,
116
+ })) {
117
+ continue;
118
+ }
119
+ tuiUpdatePackageJsonStructure({
120
+ packageJson: packageLockJson,
121
+ prevVersion,
122
+ newVersion,
123
+ isPackageLockFile: true,
124
+ ignorePackageNames,
125
+ matchPackageNames,
126
+ });
127
+ }
128
+ }
129
+ }
130
+ function isObject(value) {
131
+ return typeof value === 'object' && !!value;
132
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@taiga-ui/syncer",
3
+ "version": "0.178.0",
4
+ "description": "Taiga UI CLI tool for sync version in npm workspaces",
5
+ "keywords": [
6
+ "sync version"
7
+ ],
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/taiga-family/linters.git"
11
+ },
12
+ "license": "Apache-2.0",
13
+ "main": "./bin/src/index.js",
14
+ "bin": {
15
+ "syncer": "./bin/src/index.js"
16
+ },
17
+ "dependencies": {
18
+ "glob": "11.0.0"
19
+ },
20
+ "peerDependencies": {
21
+ "glob": "*"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ }
26
+ }