@atlaspack/parcel-to-atlaspack 2.14.2-typescript-e769947a5.0 → 2.14.2-typescript-08dcc1c9b.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/lib/bin.js +9 -0
- package/lib/cli.js +42 -0
- package/lib/migrations/diff.js +25 -0
- package/lib/migrations/migrate-package-json.js +74 -0
- package/lib/migrations/migrate-parcelrc.js +65 -0
- package/lib/migrations/package-json/migrate-config-fields.js +17 -0
- package/lib/migrations/package-json/migrate-dependencies.js +92 -0
- package/lib/migrations/package-json/migrate-engines-field.js +19 -0
- package/lib/migrations/package-json/sort-package-json-field.js +16 -0
- package/package.json +6 -6
- package/dist/bin.js +0 -9
- package/dist/cli.js +0 -30
- package/dist/migrations/diff.js +0 -16
- package/dist/migrations/migrate-package-json.js +0 -50
- package/dist/migrations/migrate-parcelrc.js +0 -44
- package/dist/migrations/package-json/migrate-config-fields.js +0 -15
- package/dist/migrations/package-json/migrate-dependencies.js +0 -82
- package/dist/migrations/package-json/migrate-engines-field.js +0 -15
- package/dist/migrations/package-json/sort-package-json-field.js +0 -11
package/lib/bin.js
ADDED
package/lib/cli.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.run = run;
|
|
7
|
+
function _commander() {
|
|
8
|
+
const data = require("commander");
|
|
9
|
+
_commander = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
var _package = _interopRequireDefault(require("../package.json"));
|
|
15
|
+
var _migratePackageJson = require("./migrations/migrate-package-json");
|
|
16
|
+
var _migrateParcelrc = require("./migrations/migrate-parcelrc");
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
async function run() {
|
|
19
|
+
const program = new (_commander().Command)();
|
|
20
|
+
program.name(_package.default.name).description('Migrate from Parcel to Atlaspack').option('--cwd <cwd>', 'The current working directory that the script will run the migration on', process.cwd()).option('--dry-run', 'Report the changes that will be made instead of making them').option('--skip-dependencies', 'Skip migrating the parcel dependencies to atlaspack').option('--skip-engines', 'Skip migrating the parcel key in package.json#engines').option('--skip-parcelrc', 'Skip migrating the .parcelrc file to .atlaspackrc').option('--tag <tag>', 'The tag used to search the npm registry for Atlaspack packages', 'canary').version(_package.default.version);
|
|
21
|
+
program.parse();
|
|
22
|
+
const {
|
|
23
|
+
cwd,
|
|
24
|
+
dryRun,
|
|
25
|
+
skipDependencies,
|
|
26
|
+
skipEngines,
|
|
27
|
+
skipParcelrc: skipParcelRc,
|
|
28
|
+
tag
|
|
29
|
+
} = program.opts();
|
|
30
|
+
|
|
31
|
+
// TODO Node API / types, parcel exe in scripts, etc
|
|
32
|
+
await Promise.all([(0, _migratePackageJson.migratePackageJson)({
|
|
33
|
+
cwd,
|
|
34
|
+
dryRun,
|
|
35
|
+
skipDependencies,
|
|
36
|
+
skipEngines,
|
|
37
|
+
tag
|
|
38
|
+
}), !skipParcelRc && (0, _migrateParcelrc.migrateParcelRc)({
|
|
39
|
+
cwd,
|
|
40
|
+
dryRun
|
|
41
|
+
})]);
|
|
42
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.diff = diff;
|
|
7
|
+
function _jestDiff() {
|
|
8
|
+
const data = require("jest-diff");
|
|
9
|
+
_jestDiff = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function diff(
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
chalk, original, modified) {
|
|
17
|
+
return (0, _jestDiff().diff)(original, modified, {
|
|
18
|
+
aAnnotation: 'Original',
|
|
19
|
+
aColor: chalk.red,
|
|
20
|
+
bAnnotation: 'Modified',
|
|
21
|
+
bColor: chalk.green,
|
|
22
|
+
expand: false,
|
|
23
|
+
omitAnnotationLines: true
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.migratePackageJson = migratePackageJson;
|
|
7
|
+
function _promises() {
|
|
8
|
+
const data = require("node:fs/promises");
|
|
9
|
+
_promises = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _nodePath() {
|
|
15
|
+
const data = require("node:path");
|
|
16
|
+
_nodePath = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _fdir() {
|
|
22
|
+
const data = require("fdir");
|
|
23
|
+
_fdir = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
var _diff = require("./diff");
|
|
29
|
+
var _migrateConfigFields = require("./package-json/migrate-config-fields");
|
|
30
|
+
var _migrateDependencies = require("./package-json/migrate-dependencies");
|
|
31
|
+
var _migrateEnginesField = require("./package-json/migrate-engines-field");
|
|
32
|
+
// TODO Update dependencies
|
|
33
|
+
async function migratePackageJson({
|
|
34
|
+
cwd,
|
|
35
|
+
dryRun,
|
|
36
|
+
skipDependencies,
|
|
37
|
+
skipEngines,
|
|
38
|
+
tag
|
|
39
|
+
}) {
|
|
40
|
+
const {
|
|
41
|
+
default: chalk
|
|
42
|
+
} = await import('chalk');
|
|
43
|
+
|
|
44
|
+
// eslint-disable-next-line no-console
|
|
45
|
+
console.log(chalk.blue('[INFO]'), 'Searching for package.json files');
|
|
46
|
+
const packageJsonPaths = await new (_fdir().fdir)().withFullPaths().exclude(dir => dir.startsWith('node_modules')).filter(path => (0, _nodePath().basename)(path) === 'package.json').crawl(cwd).withPromise();
|
|
47
|
+
const modifiedFiles = [];
|
|
48
|
+
await Promise.all(packageJsonPaths.map(async packageJsonPath => {
|
|
49
|
+
var _rawPackageJson$match;
|
|
50
|
+
const rawPackageJson = await (0, _promises().readFile)(packageJsonPath, 'utf8');
|
|
51
|
+
if (!rawPackageJson.includes('parcel')) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const packageJson = JSON.parse(rawPackageJson);
|
|
55
|
+
const didChange = [!skipEngines && (0, _migrateEnginesField.migrateEnginesField)(packageJson), (0, _migrateConfigFields.migrateConfigFields)(packageJson), !skipDependencies && (0, _migrateDependencies.migrateDependencies)(packageJson, tag)].includes(true);
|
|
56
|
+
if (!didChange) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const {
|
|
60
|
+
space = 2
|
|
61
|
+
} = ((_rawPackageJson$match = rawPackageJson.match(/^\s*{.*\n(?<space>\s*)"/)) === null || _rawPackageJson$match === void 0 ? void 0 : _rawPackageJson$match.groups) ?? {};
|
|
62
|
+
const migratedPackageJson = JSON.stringify(packageJson, null, space) + '\n';
|
|
63
|
+
if (dryRun) {
|
|
64
|
+
// eslint-disable-next-line no-console
|
|
65
|
+
console.log(chalk.blue('[INFO]'), `Updated ${(0, _nodePath().relative)(cwd, packageJsonPath)}\n${(0, _diff.diff)(chalk, rawPackageJson, migratedPackageJson)}`);
|
|
66
|
+
} else {
|
|
67
|
+
await (0, _promises().writeFile)(packageJsonPath, migratedPackageJson);
|
|
68
|
+
}
|
|
69
|
+
modifiedFiles.push(packageJsonPath);
|
|
70
|
+
}));
|
|
71
|
+
|
|
72
|
+
// eslint-disable-next-line no-console
|
|
73
|
+
console.log(chalk.blue('[INFO]'), `Migrated ${modifiedFiles.length} package.json files`);
|
|
74
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.migrateParcelRc = migrateParcelRc;
|
|
7
|
+
function _promises() {
|
|
8
|
+
const data = require("node:fs/promises");
|
|
9
|
+
_promises = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _nodePath() {
|
|
15
|
+
const data = require("node:path");
|
|
16
|
+
_nodePath = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _fdir() {
|
|
22
|
+
const data = require("fdir");
|
|
23
|
+
_fdir = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
var _diff = require("./diff");
|
|
29
|
+
// TODO: Support extended config defined in index.json?
|
|
30
|
+
async function migrateParcelRc({
|
|
31
|
+
cwd,
|
|
32
|
+
dryRun
|
|
33
|
+
}) {
|
|
34
|
+
const {
|
|
35
|
+
default: chalk
|
|
36
|
+
} = await import('chalk');
|
|
37
|
+
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
39
|
+
console.log(chalk.blue('[INFO]'), 'Searching for .parcelrc files');
|
|
40
|
+
const parcelrcPaths = await new (_fdir().fdir)().withFullPaths().exclude(dir => dir.startsWith('node_modules')).filter(path => (0, _nodePath().basename)(path).startsWith('.parcelrc')).crawl(cwd).withPromise();
|
|
41
|
+
const modifiedFiles = [];
|
|
42
|
+
await Promise.all(parcelrcPaths.map(async parcelrcPath => {
|
|
43
|
+
const parcelrc = await (0, _promises().readFile)(parcelrcPath, 'utf8');
|
|
44
|
+
const atlaspckrc = parcelrc.replace(/@parcel\//g, '@atlaspack/');
|
|
45
|
+
if (atlaspckrc !== parcelrc) {
|
|
46
|
+
if (dryRun) {
|
|
47
|
+
// eslint-disable-next-line no-console
|
|
48
|
+
console.log(chalk.blue('[INFO]'), `Updated ${(0, _nodePath().relative)(cwd, parcelrcPath)}\n${(0, _diff.diff)(chalk, parcelrc, atlaspckrc)}`);
|
|
49
|
+
} else {
|
|
50
|
+
await (0, _promises().writeFile)(parcelrcPath, atlaspckrc);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const atlaspackrcPath = (0, _nodePath().join)((0, _nodePath().dirname)(parcelrcPath), (0, _nodePath().basename)(parcelrcPath).replace('.parcelrc', '.atlaspackrc'));
|
|
54
|
+
if (dryRun) {
|
|
55
|
+
// eslint-disable-next-line no-console
|
|
56
|
+
console.log(chalk.blue('[INFO]'), `Renamed ${(0, _nodePath().relative)(cwd, parcelrcPath)}`);
|
|
57
|
+
} else {
|
|
58
|
+
await (0, _promises().rename)(parcelrcPath, atlaspackrcPath);
|
|
59
|
+
}
|
|
60
|
+
modifiedFiles.push(parcelrcPath);
|
|
61
|
+
}));
|
|
62
|
+
|
|
63
|
+
// eslint-disable-next-line no-console
|
|
64
|
+
console.log(chalk.blue('[INFO]'), `Migrated ${modifiedFiles.length} .parcelrc files`);
|
|
65
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.migrateConfigFields = migrateConfigFields;
|
|
7
|
+
// TODO Preserve order?
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
function migrateConfigFields(packageJson) {
|
|
10
|
+
let didConfigChange = false;
|
|
11
|
+
for (const field of Object.keys(packageJson).filter(key => key.startsWith('@parcel/'))) {
|
|
12
|
+
packageJson[`@atlaspack/${field.replace('@parcel/', '')}`] = packageJson[field];
|
|
13
|
+
delete packageJson[field];
|
|
14
|
+
didConfigChange = true;
|
|
15
|
+
}
|
|
16
|
+
return didConfigChange;
|
|
17
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.migrateDependencies = migrateDependencies;
|
|
7
|
+
function _child_process() {
|
|
8
|
+
const data = require("child_process");
|
|
9
|
+
_child_process = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _semver() {
|
|
15
|
+
const data = require("semver");
|
|
16
|
+
_semver = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
var _sortPackageJsonField = require("./sort-package-json-field");
|
|
22
|
+
const versions = new Map();
|
|
23
|
+
function isValidRange(range) {
|
|
24
|
+
try {
|
|
25
|
+
return !!(0, _semver().minVersion)(range);
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
27
|
+
} catch (err) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function getAtlaspackPackageName(parcelPackageName) {
|
|
32
|
+
switch (parcelPackageName) {
|
|
33
|
+
case 'parcel':
|
|
34
|
+
return '@atlaspack/cli';
|
|
35
|
+
default:
|
|
36
|
+
return `@atlaspack/${parcelPackageName.replace('@parcel/', '')}`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function getVersion(name, range, tag) {
|
|
40
|
+
let version = versions.get(name);
|
|
41
|
+
if (version) {
|
|
42
|
+
return version;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// If the range is invalid, then just use it as is
|
|
46
|
+
if (!isValidRange(range)) {
|
|
47
|
+
return range;
|
|
48
|
+
}
|
|
49
|
+
const {
|
|
50
|
+
status,
|
|
51
|
+
stdout
|
|
52
|
+
} = (0, _child_process().spawnSync)('npm', ['show', '--loglevel', 'error', `${name}@${tag}`, 'version'], {
|
|
53
|
+
stdio: ['pipe', 'pipe', 'inherit']
|
|
54
|
+
});
|
|
55
|
+
if (status) {
|
|
56
|
+
throw new Error(`Failed to retrieve canary version for ${name}`);
|
|
57
|
+
}
|
|
58
|
+
version = `^${stdout.toString().trim()}`;
|
|
59
|
+
versions.set(name, version);
|
|
60
|
+
return version;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
|
+
function migrateDependencies(packageJson, tag) {
|
|
65
|
+
let didDependenciesChange = false;
|
|
66
|
+
const skipPackages = new Set(['@parcel/hash', '@parcel/source-map', '@parcel/watcher']);
|
|
67
|
+
for (const field of ['dependencies', 'devDependencies', 'peerDependencies', 'resolutions']) {
|
|
68
|
+
if (!packageJson[field]) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
let didDependencyFieldChange = false;
|
|
72
|
+
for (const key of Object.keys(packageJson[field])) {
|
|
73
|
+
const isParcelPackage = key === 'parcel' || key.startsWith('@parcel/');
|
|
74
|
+
if (!isParcelPackage || skipPackages.has(key)) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const packageName = getAtlaspackPackageName(key);
|
|
78
|
+
const version = packageJson[field][key];
|
|
79
|
+
const nextVersion = getVersion(packageName, version, tag);
|
|
80
|
+
if (version !== nextVersion) {
|
|
81
|
+
packageJson[field][packageName] = nextVersion;
|
|
82
|
+
delete packageJson[field][key];
|
|
83
|
+
didDependencyFieldChange = true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (didDependencyFieldChange) {
|
|
87
|
+
(0, _sortPackageJsonField.sortPackageJsonField)(packageJson, field);
|
|
88
|
+
didDependenciesChange = true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return didDependenciesChange;
|
|
92
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.migrateEnginesField = migrateEnginesField;
|
|
7
|
+
var _sortPackageJsonField = require("./sort-package-json-field");
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
function migrateEnginesField(packageJson) {
|
|
10
|
+
var _packageJson$engines;
|
|
11
|
+
if (!((_packageJson$engines = packageJson.engines) !== null && _packageJson$engines !== void 0 && _packageJson$engines.parcel)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const version = packageJson.engines.parcel;
|
|
15
|
+
delete packageJson.engines.parcel;
|
|
16
|
+
packageJson.engines.atlaspack = version;
|
|
17
|
+
(0, _sortPackageJsonField.sortPackageJsonField)(packageJson, 'engines');
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.sortPackageJsonField = sortPackageJsonField;
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
function sortPackageJsonField(packageJson, field) {
|
|
9
|
+
const value = {
|
|
10
|
+
...packageJson[field]
|
|
11
|
+
};
|
|
12
|
+
packageJson[field] = {};
|
|
13
|
+
for (const key of Object.keys(value).sort()) {
|
|
14
|
+
packageJson[field][key] = value[key];
|
|
15
|
+
}
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/parcel-to-atlaspack",
|
|
3
|
-
"version": "2.14.2-typescript-
|
|
3
|
+
"version": "2.14.2-typescript-08dcc1c9b.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
7
7
|
},
|
|
8
8
|
"license": "(MIT OR Apache-2.0)",
|
|
9
|
-
"main": "
|
|
9
|
+
"main": "lib/cli.js",
|
|
10
10
|
"bin": {
|
|
11
|
-
"parcel-to-atlaspack": "
|
|
11
|
+
"parcel-to-atlaspack": "lib/bin.js"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
|
-
"
|
|
14
|
+
"lib"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
|
-
"prepack": "
|
|
17
|
+
"prepack": "chmod +x lib/bin.js",
|
|
18
18
|
"start": "ts-node src/bin.ts"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"type": "commonjs",
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "08dcc1c9bcdc6ab931d55e05ccc0f45669de2f22"
|
|
39
39
|
}
|
package/dist/bin.js
DELETED
package/dist/cli.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.run = run;
|
|
7
|
-
const commander_1 = require("commander");
|
|
8
|
-
const package_json_1 = __importDefault(require("../package.json"));
|
|
9
|
-
const migrate_package_json_1 = require("./migrations/migrate-package-json");
|
|
10
|
-
const migrate_parcelrc_1 = require("./migrations/migrate-parcelrc");
|
|
11
|
-
async function run() {
|
|
12
|
-
const program = new commander_1.Command();
|
|
13
|
-
program
|
|
14
|
-
.name(package_json_1.default.name)
|
|
15
|
-
.description('Migrate from Parcel to Atlaspack')
|
|
16
|
-
.option('--cwd <cwd>', 'The current working directory that the script will run the migration on', process.cwd())
|
|
17
|
-
.option('--dry-run', 'Report the changes that will be made instead of making them')
|
|
18
|
-
.option('--skip-dependencies', 'Skip migrating the parcel dependencies to atlaspack')
|
|
19
|
-
.option('--skip-engines', 'Skip migrating the parcel key in package.json#engines')
|
|
20
|
-
.option('--skip-parcelrc', 'Skip migrating the .parcelrc file to .atlaspackrc')
|
|
21
|
-
.option('--tag <tag>', 'The tag used to search the npm registry for Atlaspack packages', 'canary')
|
|
22
|
-
.version(package_json_1.default.version);
|
|
23
|
-
program.parse();
|
|
24
|
-
const { cwd, dryRun, skipDependencies, skipEngines, skipParcelrc: skipParcelRc, tag, } = program.opts();
|
|
25
|
-
// TODO Node API / types, parcel exe in scripts, etc
|
|
26
|
-
await Promise.all([
|
|
27
|
-
(0, migrate_package_json_1.migratePackageJson)({ cwd, dryRun, skipDependencies, skipEngines, tag }),
|
|
28
|
-
!skipParcelRc && (0, migrate_parcelrc_1.migrateParcelRc)({ cwd, dryRun }),
|
|
29
|
-
]);
|
|
30
|
-
}
|
package/dist/migrations/diff.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.diff = diff;
|
|
4
|
-
const jest_diff_1 = require("jest-diff");
|
|
5
|
-
function diff(
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
-
chalk, original, modified) {
|
|
8
|
-
return (0, jest_diff_1.diff)(original, modified, {
|
|
9
|
-
aAnnotation: 'Original',
|
|
10
|
-
aColor: chalk.red,
|
|
11
|
-
bAnnotation: 'Modified',
|
|
12
|
-
bColor: chalk.green,
|
|
13
|
-
expand: false,
|
|
14
|
-
omitAnnotationLines: true,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migratePackageJson = migratePackageJson;
|
|
4
|
-
const promises_1 = require("node:fs/promises");
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
6
|
-
const fdir_1 = require("fdir");
|
|
7
|
-
const diff_1 = require("./diff");
|
|
8
|
-
const migrate_config_fields_1 = require("./package-json/migrate-config-fields");
|
|
9
|
-
const migrate_dependencies_1 = require("./package-json/migrate-dependencies");
|
|
10
|
-
const migrate_engines_field_1 = require("./package-json/migrate-engines-field");
|
|
11
|
-
// TODO Update dependencies
|
|
12
|
-
async function migratePackageJson({ cwd, dryRun, skipDependencies, skipEngines, tag, }) {
|
|
13
|
-
const { default: chalk } = await import('chalk');
|
|
14
|
-
// eslint-disable-next-line no-console
|
|
15
|
-
console.log(chalk.blue('[INFO]'), 'Searching for package.json files');
|
|
16
|
-
const packageJsonPaths = await new fdir_1.fdir()
|
|
17
|
-
.withFullPaths()
|
|
18
|
-
.exclude((dir) => dir.startsWith('node_modules'))
|
|
19
|
-
.filter((path) => (0, node_path_1.basename)(path) === 'package.json')
|
|
20
|
-
.crawl(cwd)
|
|
21
|
-
.withPromise();
|
|
22
|
-
const modifiedFiles = [];
|
|
23
|
-
await Promise.all(packageJsonPaths.map(async (packageJsonPath) => {
|
|
24
|
-
const rawPackageJson = await (0, promises_1.readFile)(packageJsonPath, 'utf8');
|
|
25
|
-
if (!rawPackageJson.includes('parcel')) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const packageJson = JSON.parse(rawPackageJson);
|
|
29
|
-
const didChange = [
|
|
30
|
-
!skipEngines && (0, migrate_engines_field_1.migrateEnginesField)(packageJson),
|
|
31
|
-
(0, migrate_config_fields_1.migrateConfigFields)(packageJson),
|
|
32
|
-
!skipDependencies && (0, migrate_dependencies_1.migrateDependencies)(packageJson, tag),
|
|
33
|
-
].includes(true);
|
|
34
|
-
if (!didChange) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const { space = 2 } = rawPackageJson.match(/^\s*{.*\n(?<space>\s*)"/)?.groups ?? {};
|
|
38
|
-
const migratedPackageJson = JSON.stringify(packageJson, null, space) + '\n';
|
|
39
|
-
if (dryRun) {
|
|
40
|
-
// eslint-disable-next-line no-console
|
|
41
|
-
console.log(chalk.blue('[INFO]'), `Updated ${(0, node_path_1.relative)(cwd, packageJsonPath)}\n${(0, diff_1.diff)(chalk, rawPackageJson, migratedPackageJson)}`);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
await (0, promises_1.writeFile)(packageJsonPath, migratedPackageJson);
|
|
45
|
-
}
|
|
46
|
-
modifiedFiles.push(packageJsonPath);
|
|
47
|
-
}));
|
|
48
|
-
// eslint-disable-next-line no-console
|
|
49
|
-
console.log(chalk.blue('[INFO]'), `Migrated ${modifiedFiles.length} package.json files`);
|
|
50
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migrateParcelRc = migrateParcelRc;
|
|
4
|
-
const promises_1 = require("node:fs/promises");
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
6
|
-
const fdir_1 = require("fdir");
|
|
7
|
-
const diff_1 = require("./diff");
|
|
8
|
-
// TODO: Support extended config defined in index.json?
|
|
9
|
-
async function migrateParcelRc({ cwd, dryRun }) {
|
|
10
|
-
const { default: chalk } = await import('chalk');
|
|
11
|
-
// eslint-disable-next-line no-console
|
|
12
|
-
console.log(chalk.blue('[INFO]'), 'Searching for .parcelrc files');
|
|
13
|
-
const parcelrcPaths = await new fdir_1.fdir()
|
|
14
|
-
.withFullPaths()
|
|
15
|
-
.exclude((dir) => dir.startsWith('node_modules'))
|
|
16
|
-
.filter((path) => (0, node_path_1.basename)(path).startsWith('.parcelrc'))
|
|
17
|
-
.crawl(cwd)
|
|
18
|
-
.withPromise();
|
|
19
|
-
const modifiedFiles = [];
|
|
20
|
-
await Promise.all(parcelrcPaths.map(async (parcelrcPath) => {
|
|
21
|
-
const parcelrc = await (0, promises_1.readFile)(parcelrcPath, 'utf8');
|
|
22
|
-
const atlaspckrc = parcelrc.replace(/@parcel\//g, '@atlaspack/');
|
|
23
|
-
if (atlaspckrc !== parcelrc) {
|
|
24
|
-
if (dryRun) {
|
|
25
|
-
// eslint-disable-next-line no-console
|
|
26
|
-
console.log(chalk.blue('[INFO]'), `Updated ${(0, node_path_1.relative)(cwd, parcelrcPath)}\n${(0, diff_1.diff)(chalk, parcelrc, atlaspckrc)}`);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
await (0, promises_1.writeFile)(parcelrcPath, atlaspckrc);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const atlaspackrcPath = (0, node_path_1.join)((0, node_path_1.dirname)(parcelrcPath), (0, node_path_1.basename)(parcelrcPath).replace('.parcelrc', '.atlaspackrc'));
|
|
33
|
-
if (dryRun) {
|
|
34
|
-
// eslint-disable-next-line no-console
|
|
35
|
-
console.log(chalk.blue('[INFO]'), `Renamed ${(0, node_path_1.relative)(cwd, parcelrcPath)}`);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
await (0, promises_1.rename)(parcelrcPath, atlaspackrcPath);
|
|
39
|
-
}
|
|
40
|
-
modifiedFiles.push(parcelrcPath);
|
|
41
|
-
}));
|
|
42
|
-
// eslint-disable-next-line no-console
|
|
43
|
-
console.log(chalk.blue('[INFO]'), `Migrated ${modifiedFiles.length} .parcelrc files`);
|
|
44
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migrateConfigFields = migrateConfigFields;
|
|
4
|
-
// TODO Preserve order?
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
-
function migrateConfigFields(packageJson) {
|
|
7
|
-
let didConfigChange = false;
|
|
8
|
-
for (const field of Object.keys(packageJson).filter((key) => key.startsWith('@parcel/'))) {
|
|
9
|
-
packageJson[`@atlaspack/${field.replace('@parcel/', '')}`] =
|
|
10
|
-
packageJson[field];
|
|
11
|
-
delete packageJson[field];
|
|
12
|
-
didConfigChange = true;
|
|
13
|
-
}
|
|
14
|
-
return didConfigChange;
|
|
15
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migrateDependencies = migrateDependencies;
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
|
-
const semver_1 = require("semver");
|
|
6
|
-
const sort_package_json_field_1 = require("./sort-package-json-field");
|
|
7
|
-
const versions = new Map();
|
|
8
|
-
function isValidRange(range) {
|
|
9
|
-
try {
|
|
10
|
-
return !!(0, semver_1.minVersion)(range);
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
-
}
|
|
13
|
-
catch (err) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function getAtlaspackPackageName(parcelPackageName) {
|
|
18
|
-
switch (parcelPackageName) {
|
|
19
|
-
case 'parcel':
|
|
20
|
-
return '@atlaspack/cli';
|
|
21
|
-
default:
|
|
22
|
-
return `@atlaspack/${parcelPackageName.replace('@parcel/', '')}`;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function getVersion(name, range, tag) {
|
|
26
|
-
let version = versions.get(name);
|
|
27
|
-
if (version) {
|
|
28
|
-
return version;
|
|
29
|
-
}
|
|
30
|
-
// If the range is invalid, then just use it as is
|
|
31
|
-
if (!isValidRange(range)) {
|
|
32
|
-
return range;
|
|
33
|
-
}
|
|
34
|
-
const { status, stdout } = (0, child_process_1.spawnSync)('npm', ['show', '--loglevel', 'error', `${name}@${tag}`, 'version'], {
|
|
35
|
-
stdio: ['pipe', 'pipe', 'inherit'],
|
|
36
|
-
});
|
|
37
|
-
if (status) {
|
|
38
|
-
throw new Error(`Failed to retrieve canary version for ${name}`);
|
|
39
|
-
}
|
|
40
|
-
version = `^${stdout.toString().trim()}`;
|
|
41
|
-
versions.set(name, version);
|
|
42
|
-
return version;
|
|
43
|
-
}
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
-
function migrateDependencies(packageJson, tag) {
|
|
46
|
-
let didDependenciesChange = false;
|
|
47
|
-
const skipPackages = new Set([
|
|
48
|
-
'@parcel/hash',
|
|
49
|
-
'@parcel/source-map',
|
|
50
|
-
'@parcel/watcher',
|
|
51
|
-
]);
|
|
52
|
-
for (const field of [
|
|
53
|
-
'dependencies',
|
|
54
|
-
'devDependencies',
|
|
55
|
-
'peerDependencies',
|
|
56
|
-
'resolutions',
|
|
57
|
-
]) {
|
|
58
|
-
if (!packageJson[field]) {
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
let didDependencyFieldChange = false;
|
|
62
|
-
for (const key of Object.keys(packageJson[field])) {
|
|
63
|
-
const isParcelPackage = key === 'parcel' || key.startsWith('@parcel/');
|
|
64
|
-
if (!isParcelPackage || skipPackages.has(key)) {
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
const packageName = getAtlaspackPackageName(key);
|
|
68
|
-
const version = packageJson[field][key];
|
|
69
|
-
const nextVersion = getVersion(packageName, version, tag);
|
|
70
|
-
if (version !== nextVersion) {
|
|
71
|
-
packageJson[field][packageName] = nextVersion;
|
|
72
|
-
delete packageJson[field][key];
|
|
73
|
-
didDependencyFieldChange = true;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (didDependencyFieldChange) {
|
|
77
|
-
(0, sort_package_json_field_1.sortPackageJsonField)(packageJson, field);
|
|
78
|
-
didDependenciesChange = true;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return didDependenciesChange;
|
|
82
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migrateEnginesField = migrateEnginesField;
|
|
4
|
-
const sort_package_json_field_1 = require("./sort-package-json-field");
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
-
function migrateEnginesField(packageJson) {
|
|
7
|
-
if (!packageJson.engines?.parcel) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
const version = packageJson.engines.parcel;
|
|
11
|
-
delete packageJson.engines.parcel;
|
|
12
|
-
packageJson.engines.atlaspack = version;
|
|
13
|
-
(0, sort_package_json_field_1.sortPackageJsonField)(packageJson, 'engines');
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sortPackageJsonField = sortPackageJsonField;
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
-
function sortPackageJsonField(packageJson, field) {
|
|
6
|
-
const value = { ...packageJson[field] };
|
|
7
|
-
packageJson[field] = {};
|
|
8
|
-
for (const key of Object.keys(value).sort()) {
|
|
9
|
-
packageJson[field][key] = value[key];
|
|
10
|
-
}
|
|
11
|
-
}
|