Skip to content

Commit 2c9ae26

Browse files
author
Daniel Del Core
committed
removes dependency whitelisting from hypermod.configs
1 parent 30a1424 commit 2c9ae26

File tree

5 files changed

+48
-45
lines changed

5 files changed

+48
-45
lines changed

.changeset/blue-bags-try.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hypermod/cli': minor
3+
---
4+
5+
Dependency fetching is now done via the loader module on install via reading a small config in a package.json.

.changeset/old-sloths-sell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hypermod/fetcher': minor
3+
---
4+
5+
Removes whitelist dependency fetching, this approach no longer works.

packages/cli/src/main.ts

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,54 @@ import { mergeConfigs } from './utils/merge-configs';
1616
import { fetchConfigsForWorkspaces, getPackageJson } from './utils/file-system';
1717
import { getConfigPrompt, getMultiConfigPrompt } from './prompt';
1818

19-
const ExperimentalModuleLoader = () => ({
20-
install: async (packageName: string) =>
21-
await installPackage(packageName, {
22-
cwd: __dirname,
23-
packageManager: 'npm',
24-
additionalArgs: ['--force'],
25-
}),
26-
require: (packageName: string) => require(packageName),
27-
getInfo: (packageName: string) => {
19+
const ExperimentalModuleLoader = () => {
20+
const getInfo = (packageName: string) => {
2821
const entryPath = require.resolve(packageName);
2922
const location = entryPath.split(packageName)[0] + packageName;
30-
const packageJsonRaw = fs.readFileSync(
23+
const pkgJsonRaw = fs.readFileSync(
3124
path.join(location, 'package.json'),
3225
'utf8',
3326
);
27+
const pkgJson = JSON.parse(pkgJsonRaw);
3428

3529
return {
3630
location,
3731
entryPath,
38-
pkgJson: JSON.parse(packageJsonRaw),
32+
pkgJson,
3933
};
40-
},
41-
});
34+
};
35+
36+
const install = async (packageName: string) => {
37+
await installPackage(packageName, {
38+
cwd: __dirname,
39+
packageManager: 'npm',
40+
additionalArgs: ['--force'],
41+
});
42+
43+
const { pkgJson } = getInfo(packageName);
44+
45+
// Install whitelisted devDependencies
46+
if (pkgJson?.hypermod?.dependencies) {
47+
await Promise.all(
48+
pkgJson.hypermod.dependencies.map((dep: string) => {
49+
const version = pkgJson.devDependencies[dep];
50+
if (!version) return;
51+
return installPackage(`${dep}@${version}`, {
52+
cwd: __dirname,
53+
packageManager: 'npm',
54+
additionalArgs: ['--force'],
55+
});
56+
}),
57+
);
58+
}
59+
};
60+
61+
return {
62+
install,
63+
getInfo,
64+
require: (packageName: string) => require(packageName),
65+
};
66+
};
4267

4368
export default async function main(
4469
paths: string[],

packages/fetcher/src/index.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -147,26 +147,6 @@ export async function fetchRemotePackage(
147147
const pkg = packageManager.require(packageName);
148148
const configExport = resolveConfigExport(pkg);
149149

150-
// Install whitelisted deps
151-
if (
152-
// @ts-expect-error legacy module loader doesn't know about these properties
153-
info.pkgJson &&
154-
// @ts-expect-error legacy module loader doesn't know about these properties
155-
info.pkgJson.devDependencies &&
156-
configExport.dependencies
157-
) {
158-
await Promise.all(
159-
configExport.dependencies.map(dep => {
160-
// @ts-expect-error legacy module loader doesn't know about these properties
161-
const version = info.pkgJson.devDependencies[dep];
162-
163-
if (!version) return;
164-
165-
return packageManager.install(`${dep}@${version}`);
166-
}),
167-
);
168-
}
169-
170150
if (configExport.transforms || configExport.presets) {
171151
return {
172152
filePath: info.location,

website/docs/configuration.mdx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,3 @@ Targets list the packages that the codemod package targets.
6565
This is useful for Hypermod packages that have codemods targeting multiple related packages at the same time, such as packages from a monorepo.
6666

6767
For example: `targets: ['@foo/bar', '@foo/baz']`
68-
69-
### `dependencies`
70-
71-
(Experimental feature, this will only work when the `--experimental-loader` flag is specified)
72-
73-
A list of dependencies to be installed before running the transform. These are useful when co-locating codemods with an existing
74-
package and want to specify a whitelist of `devDependencies` to be installed only when run via `@hypermod/cli`.
75-
This avoids codemod-related dependencies from unnecessarily increasing the bundlesize for regular consumers of the package.
76-
77-
Note: the versions installed are based on what's specified in the `package.json`
78-
79-
Example: `dependencies: ['@hypermod/utils', 'postcss', 'postcss-less']`

0 commit comments

Comments
 (0)