Skip to content

Commit

Permalink
Merge branch 'main' into pfx-793
Browse files Browse the repository at this point in the history
  • Loading branch information
jpina1-godaddy authored Nov 22, 2024
2 parents 2f82666 + 1018559 commit 979124f
Show file tree
Hide file tree
Showing 13 changed files with 1,236 additions and 41 deletions.
1,190 changes: 1,183 additions & 7 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/gasket-plugin-metadata/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# `@gasket/plugin-metadata`

- Convert plugin to ESM ([#978])

### 7.0.0

- See [Version 7 Upgrade Guide] for overall changes
Expand Down Expand Up @@ -79,6 +81,7 @@
[#597]: https://github.com/godaddy/gasket/pull/597
[#613]: https://github.com/godaddy/gasket/pull/613
[#695]: https://github.com/godaddy/gasket/pull/695
[#978]: https://github.com/godaddy/gasket/pull/978

[Loader]:/packages/gasket-resolve/docs/api.md#loader
[PluginInfo]:/packages/gasket-resolve/docs/api.md#plugininfo
Expand Down
11 changes: 7 additions & 4 deletions packages/gasket-plugin-metadata/lib/actions.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
const path = require('path');
import path from 'path';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);

const isModulePath = /^[/.]|^[a-zA-Z]:\\|node_modules/;
const isGasketModule = /(@gasket\/|gasket-)(?!plugin)(?!preset).+/;
const isGasketPreset = /(gasket-preset)|(@gasket\/preset-)/;
const isGasketPlugin = /(gasket-plugin)|(@gasket\/plugin-)/;
let _metadata;

function tryRequire(path) {
function tryRequire(tryPath) {
try {
return require(path);
return require(tryPath);
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
return null;
Expand Down Expand Up @@ -109,6 +112,6 @@ async function getMetadata(gasket) {
return _metadata;
}

module.exports = {
export default {
getMetadata
};
6 changes: 4 additions & 2 deletions packages/gasket-plugin-metadata/lib/create.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { name, version } = require('../package.json');

/** @type {import('@gasket/core').HookHandler<'create'>} */
module.exports = function create(gasket, { pkg, gasketConfig }) {
export default function create(gasket, { pkg, gasketConfig }) {
gasketConfig.addPlugin('pluginMetadata', name);
pkg.add('dependencies', {
[name]: `^${version}`
});
};
}
12 changes: 7 additions & 5 deletions packages/gasket-plugin-metadata/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const create = require('./create');
const actions = require('./actions');
const webpackConfig = require('./webpack-config');
import create from './create.js';
import actions from './actions.js';
import webpackConfig from './webpack-config.js';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { name, version, description } = require('../package.json');

/** @type {import('@gasket/core').Plugin} */
module.exports = {
export default ({
name,
version,
description,
Expand Down Expand Up @@ -41,4 +43,4 @@ module.exports = {
};
}
}
};
});
7 changes: 5 additions & 2 deletions packages/gasket-plugin-metadata/lib/webpack-config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/// <reference types="@gasket/plugin-webpack" />

import { createRequire } from 'module';
const require = createRequire(import.meta.url);

const { name } = require('../package.json');

/** @type {import('@gasket/core').HookHandler<'webpackConfig'>} */
module.exports = function webpackConfigHook(gasket, webpackConfig) {
export default function webpackConfigHook(gasket, webpackConfig) {
webpackConfig.resolve.alias[name] = false;
return webpackConfig;
};
}
9 changes: 4 additions & 5 deletions packages/gasket-plugin-metadata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"files": [
"lib"
],
"type": "module",
"scripts": {
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix",
"test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict' jest",
"test": "vitest --watch=false --globals",
"test:watch": "npm run test -- --watch",
"test:coverage": "npm run test -- --coverage",
"posttest": "npm run lint && npm run typecheck",
Expand Down Expand Up @@ -41,16 +42,14 @@
},
"devDependencies": {
"@godaddy/dmd": "^1.0.4",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.5",
"cross-env": "^7.0.3",
"eslint": "^8.56.0",
"eslint-config-godaddy": "^7.1.1",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-unicorn": "^55.0.0",
"jest": "^29.7.0",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"vitest": "^2.1.5"
},
"eslintConfig": {
"extends": [
Expand Down
17 changes: 9 additions & 8 deletions packages/gasket-plugin-metadata/test/actions.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { vi } from 'vitest';

const mockPlugin = {
name: 'mock',
hooks: {
Expand All @@ -22,10 +24,9 @@ describe('actions', () => {
actions;

beforeEach(async function () {
delete require.cache[require.resolve('../lib/actions')];
actions = require('../lib/actions');
applyStub = jest.fn();
handlerStub = jest.fn();
actions = (await import('../lib/actions.js')).default;
applyStub = vi.fn();
handlerStub = vi.fn();

gasket = {
config: {
Expand All @@ -45,8 +46,8 @@ describe('actions', () => {
});

afterEach(() => {
jest.clearAllMocks();
jest.resetModules();
vi.clearAllMocks();
vi.resetModules();
});

it('returns an actions object', () => {
Expand All @@ -58,13 +59,13 @@ describe('actions', () => {
});

it('calls execApply metadata lifecycle', async () => {
jest.spyOn(require, 'resolve').mockResolvedValueOnce();
vi.spyOn(require, 'resolve').mockResolvedValueOnce();
await actions.getMetadata(gasket);
expect(applyStub).toHaveBeenCalled();
});

it('memoizes metadata & calls lifecycle once', async () => {
jest.spyOn(require, 'resolve').mockResolvedValueOnce();
vi.spyOn(require, 'resolve').mockResolvedValueOnce();
await actions.getMetadata(gasket);
await actions.getMetadata(gasket);
expect(applyStub).toHaveBeenCalledTimes(1);
Expand Down
11 changes: 7 additions & 4 deletions packages/gasket-plugin-metadata/test/create.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
const plugin = require('../');
const { name, version } = require('../package.json');
import { vi } from 'vitest';
import plugin from '../lib/index.js';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { name, version } = require('../package');

describe('create', () => {
let mockContext;

beforeEach(() => {
mockContext = {
pkg: {
add: jest.fn()
add: vi.fn()
},
gasketConfig: {
addPlugin: jest.fn()
addPlugin: vi.fn()
}
};
});
Expand Down
4 changes: 3 additions & 1 deletion packages/gasket-plugin-metadata/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable max-statements */
const plugin = require('../');
import plugin from '../lib/index.js';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { name, version, description } = require('../package');

describe('Plugin', function () {
Expand Down
4 changes: 3 additions & 1 deletion packages/gasket-plugin-metadata/test/webpack-config.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const webpackConfigHook = require('../lib/webpack-config');
import webpackConfigHook from '../lib/webpack-config';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { name } = require('../package');

describe('webpackConfig', function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-plugin-metadata/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"skipLibCheck": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"module": "nodenext",
"lib": [
"esnext",
"dom"
],
"types": [
"@types/jest",
"@types/node",
"@gasket/plugin-logger"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Gasket, Hook, GasketActions } from '@gasket/core';
import type { PluginData, Metadata } from '@gasket/plugin-metadata';
import '@gasket/plugin-metadata';

describe('@gasket/plugin-metadata', () => {
type SlimGasket = Omit<Gasket,
Expand Down

0 comments on commit 979124f

Please sign in to comment.