Skip to content

Commit

Permalink
fix: migrate on full ESM code
Browse files Browse the repository at this point in the history
BREAKING CHANGE: remove esm module and use native ESM module convention
  • Loading branch information
Romakita committed Feb 3, 2024
1 parent 5e03f5d commit 6d08b1d
Show file tree
Hide file tree
Showing 27 changed files with 3,334 additions and 7,785 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.24.1",
"description": "Monorepo CLI and utils to deploy packages on NPM",
"private": true,
"type": "module",
"scripts": {
"clean": "node packages/monorepo/bin/monorepo-clean workspace",
"test": "yarn test:lint",
Expand All @@ -29,11 +30,9 @@
"devDependencies": {
"eslint": "8.56.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-jest": "27.6.3",
"eslint-plugin-prettier": "5.1.3",
"husky": "8.0.1",
"lint-staged": "10.5.4",
"microbundle": "0.13.0",
"prettier": "3.2.4",
"semantic-release": "23.0.0"
},
Expand Down
5 changes: 2 additions & 3 deletions packages/monorepo/bin/monorepo-build.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/usr/bin/env node
const commander = require("commander");
const {runCommand, commands} = require("../src/index.js");

commander
.usage("monorepo build [options]")
.option("-v, --verbose", "Enable verbose log", (v, t) => t + 1, 0)
.parse(process.argv);

(() => {
const {commands, runCommand} = import("../src");
(async () => {
const {commands, runCommand} = await import("../src/index.js");

runCommand(commands.BuildCmd, commander.opts());
})();
5 changes: 3 additions & 2 deletions packages/monorepo/bin/monorepo-ci.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env node
const commander = require("commander");
const {commands, runCommand} = require("../src");

commander
.usage("monorepo ci <type> [options]")
.arguments("<type>")
.option("-v, --verbose", "Enable verbose log", (v, t) => t + 1, 0)
.action((type) => {
.action(async (type) => {
const {commands, runCommand} = await import("../src/index.js");

runCommand(commands.CICmd, {
type,
verbose: !!commander.opts().verbose
Expand Down
5 changes: 3 additions & 2 deletions packages/monorepo/bin/monorepo-clean.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env node
const commander = require("commander");
const {commands, runCommand} = require("../src");

commander
.usage("monorepo clean <type> [options]")
.arguments("<type>")
.option("-v, --verbose", "Enable verbose log", (v, t) => t + 1, 0)
.action((type) => {
.action(async (type) => {
const {commands, runCommand} = await import("../src/index.js");

runCommand(commands.CleanCmd, {
type,
verbose: !!commander.opts().verbose
Expand Down
5 changes: 3 additions & 2 deletions packages/monorepo/bin/monorepo-publish.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env node
const commander = require("commander");
const {commands, runCommand} = require("../src");

commander
.usage("monorepo publish <type> [options]")
.arguments("<type>")
.option("-v, --verbose", "Enable verbose log", (v, t) => t + 1, 0)
.option("-d, --dry-run", "Run publish in dryRun mode", (v, t) => t + 1, 0)
.action((type) => {
.action(async (type) => {
const {commands, runCommand} = await import("../src/index.js");
const options = commander.opts();

runCommand(commands.PublishCmd, {
type,
verbose: !!options.verbose,
Expand Down
6 changes: 4 additions & 2 deletions packages/monorepo/bin/monorepo-sync.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env node
const commander = require("commander");
const {commands, runCommand} = require("../src");

commander
.usage("monorepo sync <type> [options]")
.arguments("<type>")
.option("-v, --verbose", "Enable verbose log", (v, t) => t + 1, 0)
.action((type) => {
.action(async (type) => {
const {commands, runCommand} = await require("../src/index.js");

const options = commander.opts();

runCommand(commands.SyncCmd, {
type,
verbose: !!options.verbose
Expand Down
4 changes: 2 additions & 2 deletions packages/monorepo/bin/monorepo-version.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env node
const commander = require("commander");
const {commands, runCommand} = require("../src");

commander
.usage("monorepo version <version>")
.arguments("<version>")
.option("-v, --verbose", "Enable verbose log", (v, t) => t + 1, 0)
.action((version) => {
.action(async (version) => {
const {commands, runCommand} = await import("../src/index.js");
runCommand(commands.VersionCmd, {
version,
verbose: !!commander.opts().verbose
Expand Down
3 changes: 3 additions & 0 deletions packages/monorepo/bin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
33 changes: 21 additions & 12 deletions packages/monorepo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "@tsed/monorepo-utils",
"version": "1.24.1",
"description": "Mono repo utils",
"type": "module",
"main": "./src/index.js",
"exports": {
".": "./src/index.js",
"./semantic-release": "./semantic-release.js"
},
"bin": {
"monorepo": "./bin/monorepo.js"
},
Expand All @@ -22,23 +27,27 @@
"bin": "./bin"
},
"dependencies": {
"@samverschueren/stream-to-observable": "0.3.1",
"@typescript-eslint/typescript-estree": "6.20.0",
"any-observable": "0.5.1",
"axios": "0.27.2",
"chalk": "4.1.2",
"commander": "9.4.0",
"esm": "3.2.25",
"execa": "5.0.1",
"axios": "1.6.7",
"chalk": "5.3.0",
"commander": "11.1.0",
"execa": "8.0.1",
"fancy-log": "1.3.3",
"figures": "3.2.0",
"fs-extra": "10.1.0",
"globby": "11.1.0",
"has-yarn": "2.1.0",
"inquirer": "7.3.3",
"listr": "0.14.3",
"fs-extra": "11.2.0",
"globby": "14.0.0",
"has-yarn": "3.0.0",
"inquirer": "9.2.13",
"jsonfile": "^6.1.0",
"listr2": "8.0.2",
"lodash": "4.17.21",
"normalize-path": "3.0.0",
"semver": "7.3.7",
"split": "1.0.1"
"rxjs": "7.8.1",
"semver": "7.5.4",
"split": "1.0.1",
"typescript": "5.3.3"
},
"peerDependencies": {
"semantic-release": ">=19"
Expand Down
51 changes: 25 additions & 26 deletions packages/monorepo/semantic-release.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
const {MonoRepo} = require("./src");
import {MonoRepo} from "./src/index.js";

/**
* @type {MonoRepo}
*/
let monoRepo;

module.exports = {
async verifyConditions(pluginConfig, context) {
monoRepo = new MonoRepo({
rootDir: context.cwd
});
export async function verifyConditions(pluginConfig, context) {
monoRepo = new MonoRepo({
rootDir: context.cwd
});

await monoRepo.configureWorkspace({
dryRun: pluginConfig.dryRun
});
},
await monoRepo.configureWorkspace({
dryRun: pluginConfig.dryRun
});
}

async prepare(pluginConfig, context) {
const {
nextRelease: {version}
} = context;
export async function prepare(pluginConfig, context) {
const {
nextRelease: {version}
} = context;

await monoRepo.newVersion({version});
await monoRepo.build("workspace");
await monoRepo.commitChanges({version});
},
await monoRepo.newVersion({version});
await monoRepo.build("workspace");
await monoRepo.commitChanges({version});
}

async publish(pluginConfig) {
return monoRepo.publish("packages", {dryRun: pluginConfig.dryRun});
},
export async function publish(pluginConfig) {
return monoRepo.publish("packages", {dryRun: pluginConfig.dryRun});
}

async success(pluginConfig) {
if (!pluginConfig.dryRun) {
return monoRepo.sync("repository");
}
export async function success(pluginConfig) {
if (!pluginConfig.dryRun) {
return monoRepo.sync("repository");
}
};
}
62 changes: 31 additions & 31 deletions packages/monorepo/src/MonoRepo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {get} from "lodash";
import _ from "lodash";
import hasYarn from "has-yarn";
import logger from "fancy-log";
import {join} from "path";
Expand Down Expand Up @@ -27,19 +27,19 @@ import {yarnBerry} from "./utils/cli/YarnBerry.js";

function getDefaultOptions(rootPkg) {
return {
version: get(rootPkg, "version"),
outputDir: get(rootPkg, "monorepo.outputDir", "./dist"),
npmAccess: get(rootPkg, "monorepo.npmAccess", "public"),
npmDistTag: get(rootPkg, "monorepo.npmDistTag", get(rootPkg, "publishConfig.tag")),
skipNpmPublish: get(rootPkg, "monorepo.skipNpmPublish", false),
productionBranch: get(rootPkg, "monorepo.productionBranch", "master"),
developBranch: get(rootPkg, "monorepo.developBranch", "master"),
origin: get(rootPkg, "monorepo.origin", "origin"),
registry: get(rootPkg, "publishConfig.registry", "https://registry.npmjs.org/"),
registries: get(rootPkg, "monorepo.registries", []),
repositoryUrl: get(rootPkg, "repository.url", get(rootPkg, "repository")),
ignoreSyncDependencies: get(rootPkg, "monorepo.ignoreSyncDependencies", []),
buildCmd: get(rootPkg, "monorepo.buildCmd", "build")
version: _.get(rootPkg, "version"),
outputDir: _.get(rootPkg, "monorepo.outputDir", "./dist"),
npmAccess: _.get(rootPkg, "monorepo.npmAccess", "public"),
npmDistTag: _.get(rootPkg, "monorepo.npmDistTag", _.get(rootPkg, "publishConfig.tag")),
skipNpmPublish: _.get(rootPkg, "monorepo.skipNpmPublish", false),
productionBranch: _.get(rootPkg, "monorepo.productionBranch", "master"),
developBranch: _.get(rootPkg, "monorepo.developBranch", "master"),
origin: _.get(rootPkg, "monorepo.origin", "origin"),
registry: _.get(rootPkg, "publishConfig.registry", "https://registry.npmjs.org/"),
registries: _.get(rootPkg, "monorepo.registries", []),
repositoryUrl: _.get(rootPkg, "repository.url", _.get(rootPkg, "repository")),
ignoreSyncDependencies: _.get(rootPkg, "monorepo.ignoreSyncDependencies", []),
buildCmd: _.get(rootPkg, "monorepo.buildCmd", "build")
};
}

Expand Down Expand Up @@ -114,7 +114,7 @@ export class MonoRepo {
* @type {string}
* @public
*/
this.version = version || get(this.rootPkg, "version");
this.version = version || _.get(this.rootPkg, "version");
/**
* @type {string}
* @public
Expand Down Expand Up @@ -203,20 +203,20 @@ export class MonoRepo {
this.dryRun = dryRun;

// DOC
this.ghpages = get(this.rootPkg, "monorepo.ghpages", []).map((item) => {
this.ghpages = _.get(this.rootPkg, "monorepo.ghpages", []).map((item) => {
return {
...item,
dir: get(item, "dir", ""),
url: get(item, "url", this.repositoryUrl),
branch: get(item, "branch", "gh-pages"),
cname: get(item, "cname", "")
dir: _.get(item, "dir", ""),
url: _.get(item, "url", this.repositoryUrl),
branch: _.get(item, "branch", "gh-pages"),
cname: _.get(item, "cname", "")
};
});

// EXAMPLES
this.examples = {
dir: get(this.rootPkg, "monorepo.examples.dir", "./examples"),
repositories: get(this.rootPkg, "monorepo.examples.repositories", {}),
dir: _.get(this.rootPkg, "monorepo.examples.dir", "./examples"),
repositories: _.get(this.rootPkg, "monorepo.examples.repositories", {}),
...(options.examples || {})
};

Expand All @@ -226,17 +226,17 @@ export class MonoRepo {
* @type {string}
* @public
*/
app: this.env.HEROKU_APP || get(this.rootPkg, "monorepo.heroku.app", ""),
app: this.env.HEROKU_APP || _.get(this.rootPkg, "monorepo.heroku.app", ""),
/**
* @type {string}
* @public
*/
apiKey: this.env.HEROKU_API_KEY || get(this.rootPkg, "monorepo.heroku.apiKey", ""),
apiKey: this.env.HEROKU_API_KEY || _.get(this.rootPkg, "monorepo.heroku.apiKey", ""),
/**
* @type {string}
* @public
*/
team: this.env.HEROKU_TEAM || get(this.rootPkg, "monorepo.heroku.team", ""),
team: this.env.HEROKU_TEAM || _.get(this.rootPkg, "monorepo.heroku.team", ""),
...(options.heroku || {})
};

Expand All @@ -246,17 +246,17 @@ export class MonoRepo {
* @type {string}
* @public
*/
repository: this.env.DOCKER_REPOSITORY || get(this.rootPkg, "monorepo.dockerhub.repository", ""),
repository: this.env.DOCKER_REPOSITORY || _.get(this.rootPkg, "monorepo.dockerhub.repository", ""),
/**
* @type {string}
* @public
*/
id: this.env.DOCKER_HUB_ID || get(this.rootPkg, "monorepo.dockerhub.id", ""),
id: this.env.DOCKER_HUB_ID || _.get(this.rootPkg, "monorepo.dockerhub.id", ""),
/**
* @type {string}
* @public
*/
pwd: this.env.DOCKER_HUB_PWD || get(this.rootPkg, "monorepo.dockerhub.pwd", ""),
pwd: this.env.DOCKER_HUB_PWD || _.get(this.rootPkg, "monorepo.dockerhub.pwd", ""),
...(options.dockerhub || {})
};
}
Expand Down Expand Up @@ -302,15 +302,15 @@ export class MonoRepo {
}

get hasLerna() {
return Boolean(get(this.rootPkg, "dependencies.lerna") || get(this.rootPkg, "devDependencies.lerna"));
return Boolean(_.get(this.rootPkg, "dependencies.lerna") || _.get(this.rootPkg, "devDependencies.lerna"));
}

get hasNx() {
return Boolean(get(this.rootPkg, "dependencies.nx") || get(this.rootPkg, "devDependencies.nx"));
return Boolean(_.get(this.rootPkg, "dependencies.nx") || _.get(this.rootPkg, "devDependencies.nx"));
}

get hasBuild() {
return Boolean(get(this.rootPkg, "scripts.build"));
return Boolean(_.get(this.rootPkg, "scripts.build"));
}

get hasE2E() {
Expand Down
12 changes: 6 additions & 6 deletions packages/monorepo/src/commands/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./clean/CleanCmd";
export * from "./build/BuildCmd";
export * from "./version/VersionCmd";
export * from "./publish/PublishCmd";
export * from "./sync/SyncCmd";
export * from "./ci/CICmd";
export * from "./clean/CleanCmd.js";
export * from "./build/BuildCmd.js";
export * from "./version/VersionCmd.js";
export * from "./publish/PublishCmd.js";
export * from "./sync/SyncCmd.js";
export * from "./ci/CICmd.js";
Loading

0 comments on commit 6d08b1d

Please sign in to comment.