Skip to content

Commit

Permalink
Refactor to support release-it@15 (ESM)
Browse files Browse the repository at this point in the history
  • Loading branch information
refi93 committed Jul 7, 2022
1 parent 189e32f commit 4aabff0
Show file tree
Hide file tree
Showing 8 changed files with 3,213 additions and 2,463 deletions.
20 changes: 0 additions & 20 deletions .eslintrc.js

This file was deleted.

20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"root": true,
"extends": ["eslint:recommended", "plugin:node/recommended", "plugin:prettier/recommended"],
"plugins": ["prettier", "node"],
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
},
"env": {
"node": true
},
"overrides": [
{
"files": ["jest.setup.js", "__tests__/**/*.js"],
"env": {
"jest": true
}
}
]
}
45 changes: 25 additions & 20 deletions __tests__/plugin-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const fs = require('fs');
const { createTempDir } = require('broccoli-test-helper');
const { factory, runTasks } = require('release-it/test/util');
const Shell = require('release-it/lib/shell');
const Plugin = require('../index');
import fs from 'fs';
import _ from 'lodash';
import { createTempDir } from 'broccoli-test-helper';
import { factory, runTasks } from 'release-it/test/util';
import Plugin from '../index';

const namespace = 'release-it-yarn-workspaces';

Expand Down Expand Up @@ -78,7 +78,12 @@ function buildPlugin(config = {}, _Plugin = TestPlugin) {
// we work around the same relative issue by storing the commands executed,
// and intercepting them to return replacement values (this is done in
// execFormattedCommand just below)
container.shell.exec = Shell.prototype.exec;
container.shell.exec = (command, options, context) => {
if (!command || !command.length) return;
return typeof command === 'string'
? container.shell.execFormattedCommand(_.template(command)(context), options)
: container.shell.execFormattedCommand(command, options);
};
container.shell.execFormattedCommand = async (command, options) => {
const operation = {
operationType: 'command',
Expand Down Expand Up @@ -195,12 +200,12 @@ describe('release-it-yarn-workspaces', () => {
Object {
"command": "npm ping --registry https://registry.npmjs.org",
"operationType": "command",
"options": Object {},
"options": undefined,
},
Object {
"command": "npm whoami --registry https://registry.npmjs.org",
"operationType": "command",
"options": Object {},
"options": undefined,
},
Object {
"command": "npm publish ./packages/bar --tag latest",
Expand Down Expand Up @@ -387,12 +392,12 @@ describe('release-it-yarn-workspaces', () => {
Object {
"command": "npm ping --registry https://registry.npmjs.org",
"operationType": "command",
"options": Object {},
"options": undefined,
},
Object {
"command": "npm whoami --registry https://registry.npmjs.org",
"operationType": "command",
"options": Object {},
"options": undefined,
},
Object {
"command": "npm publish ./packages/@scope-name/bar --tag latest",
Expand Down Expand Up @@ -465,12 +470,12 @@ describe('release-it-yarn-workspaces', () => {
Object {
"command": "npm ping --registry https://registry.npmjs.org",
"operationType": "command",
"options": Object {},
"options": undefined,
},
Object {
"command": "npm whoami --registry https://registry.npmjs.org",
"operationType": "command",
"options": Object {},
"options": undefined,
},
Object {
"command": "npm publish ./dist/packages/qux --tag latest",
Expand Down Expand Up @@ -512,12 +517,12 @@ describe('release-it-yarn-workspaces', () => {
Object {
"command": "npm ping --registry https://registry.npmjs.org",
"operationType": "command",
"options": Object {},
"options": undefined,
},
Object {
"command": "npm whoami --registry https://registry.npmjs.org",
"operationType": "command",
"options": Object {},
"options": undefined,
},
Object {
"command": "npm publish ./packages/bar --tag foo",
Expand Down Expand Up @@ -598,12 +603,12 @@ describe('release-it-yarn-workspaces', () => {
Object {
"command": "npm ping --registry https://registry.npmjs.org",
"operationType": "command",
"options": Object {},
"options": undefined,
},
Object {
"command": "npm whoami --registry https://registry.npmjs.org",
"operationType": "command",
"options": Object {},
"options": undefined,
},
Object {
"command": "npm publish ./packages/bar --tag beta",
Expand Down Expand Up @@ -658,12 +663,12 @@ describe('release-it-yarn-workspaces', () => {
Object {
"command": "npm ping --registry https://registry.npmjs.org",
"operationType": "command",
"options": Object {},
"options": undefined,
},
Object {
"command": "npm whoami --registry https://registry.npmjs.org",
"operationType": "command",
"options": Object {},
"options": undefined,
},
Object {
"command": "npm publish ./packages/bar --tag latest",
Expand Down Expand Up @@ -765,12 +770,12 @@ describe('release-it-yarn-workspaces', () => {
Object {
"command": "npm ping --registry https://registry.npmjs.org",
"operationType": "command",
"options": Object {},
"options": undefined,
},
Object {
"command": "npm whoami --registry https://registry.npmjs.org",
"operationType": "command",
"options": Object {},
"options": undefined,
},
Object {
"command": "npm publish ./dist/@glimmer/interfaces --tag latest",
Expand Down
32 changes: 19 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const fs = require('fs');
const path = require('path');
const semver = require('semver');
const urlJoin = require('url-join');
const walkSync = require('walk-sync');
const detectNewline = require('detect-newline');
const detectIndent = require('detect-indent');
const { Plugin } = require('release-it');

require('validate-peer-dependencies')(__dirname);
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import semver from 'semver';
import urlJoin from 'url-join';
import walkSync from 'walk-sync';
import detectNewline from 'detect-newline';
import detectIndent from 'detect-indent';
import { Plugin } from 'release-it';
import validatePeerDependencies from 'validate-peer-dependencies';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
validatePeerDependencies(__dirname);

const options = { write: false };

Expand Down Expand Up @@ -114,7 +118,7 @@ class JSONFile {
}
}

module.exports = class YarnWorkspacesPlugin extends Plugin {
export default class YarnWorkspacesPlugin extends Plugin {
static isEnabled(options) {
return fs.existsSync(ROOT_MANIFEST_PATH) && options !== false;
}
Expand Down Expand Up @@ -146,7 +150,9 @@ module.exports = class YarnWorkspacesPlugin extends Plugin {
},
});

const { publishConfig, workspaces } = require(path.resolve(ROOT_MANIFEST_PATH));
const { publishConfig, workspaces } = JSON.parse(
fs.readFileSync(path.resolve(ROOT_MANIFEST_PATH))
);

this.setContext({
publishConfig,
Expand Down Expand Up @@ -522,4 +528,4 @@ module.exports = class YarnWorkspacesPlugin extends Plugin {

return this._workspaces;
}
};
}
9 changes: 8 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
module.exports = {
export default {
setupFilesAfterEnv: ['./jest.setup.js'],
moduleFileExtensions: ['js', 'ts', 'mjs'],
transform: {
'^.+\\.[t|j]sx?$': 'babel-jest',
},
moduleNameMapper: {
'#(.*)': '<rootDir>/node_modules/$1',
},
};
2 changes: 2 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
import { jest } from '@jest/globals';

jest.setTimeout(30000);
22 changes: 13 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
"repository": "https://github.com/rwjblue/release-it-yarn-workspaces",
"license": "MIT",
"author": "Robert Jackson <me@rwjblue.com>",
"type": "module",
"main": "index.js",
"files": [
"index.js"
],
"scripts": {
"lint:js": "eslint .",
"test": "npm-run-all lint:js test:jest",
"test:jest": "jest"
"test:jest": "NODE_OPTIONS=--experimental-vm-modules yarn jest"
},
"husky": {
"hooks": {
Expand All @@ -37,23 +38,26 @@
"walk-sync": "^2.0.2"
},
"devDependencies": {
"@jest/globals": "^28.1.2",
"broccoli-test-helper": "^2.0.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint": "^8.19.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^4.2.3",
"jest": "^25.2.3",
"jest": "^28.1.2",
"jest-environment-node": "^28.1.2",
"lint-staged": "^10.1.1",
"lodash": "^4.17.21",
"npm-run-all": "^4.1.5",
"prettier": "^2.0.2",
"release-it": "^14.0.0",
"release-it-lerna-changelog": "^3.0.0",
"release-it": "^15.1.1",
"release-it-lerna-changelog": "^4.0.1",
"sinon": "^9.0.1",
"tmp": "^0.1.0"
},
"peerDependencies": {
"release-it": "^14.0.0"
"release-it": "^15.0.0"
},
"engines": {
"node": "10.* || 12.* || >= 14"
Expand Down
Loading

0 comments on commit 4aabff0

Please sign in to comment.