Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to support release-it@15 (ESM) #73

Merged
merged 8 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ module.exports = {
extends: ['eslint:recommended', 'plugin:node/recommended', 'plugin:prettier/recommended'],
plugins: ['prettier', 'node'],
parserOptions: {
ecmaVersion: 2017,
sourceType: 'script',
ecmaVersion: 2022,
sourceType: 'module',
},
env: {
node: true,
},
rules: {
'node/no-missing-import': [
'error',
{
// ignoring `release-it` as a devDep since there's an expectation that it's installed in the host package
allowModules: ['release-it'],
},
],
},
overrides: [
{
files: ['jest.setup.js', '__tests__/**/*.js'],
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
node-version: [14.x, 16.x]

steps:
- uses: actions/checkout@v1
Expand All @@ -34,7 +34,7 @@ jobs:

strategy:
matrix:
release-it-version: ["14.0.0", "14.1.0", "14.2.0"]
release-it-version: ["14.0.0", "14.1.0", "14.2.0", "15.0.0", "15.1.1"]

steps:
- uses: actions/checkout@v1
Expand Down
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.js';

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) => {
scalvert marked this conversation as resolved.
Show resolved Hide resolved
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);
scalvert marked this conversation as resolved.
Show resolved Hide resolved
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',
scalvert marked this conversation as resolved.
Show resolved Hide resolved
},
};
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);
24 changes: 14 additions & 10 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,26 +38,29 @@
"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",
scalvert marked this conversation as resolved.
Show resolved Hide resolved
"sinon": "^9.0.1",
"tmp": "^0.1.0"
},
"peerDependencies": {
"release-it": "^14.0.0"
"release-it": "^14.0.0 || ^15.0.0"
},
"engines": {
"node": "10.* || 12.* || >= 14"
"node": ">= 14"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
Expand Down
Loading