mirror of
https://github.com/actions/setup-node.git
synced 2025-08-26 18:44:18 +00:00
update the field
This commit is contained in:
parent
85d6eeb440
commit
72899a8e31
@ -137,7 +137,7 @@ It's **always** recommended to commit the lockfile of your package manager for s
|
||||
|
||||
The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under the hood for caching global packages data but requires less configuration settings. Supported package managers are `npm`, `yarn`, `pnpm` (v6.10+). The `cache` input is optional.
|
||||
|
||||
Caching is turned on by default when a `packageManager` or `devEngines.packageManager` field is detected in the `package.json` file. The `package-manager-cache` input provides control over this automatic caching behavior. By default, `package-manager-cache` is set to `true`, which enables caching when a valid package manager field is detected in the `package.json` file. To disable this automatic caching, set the `package-manager-cache` input to `false`.
|
||||
Caching is turned on by default when a `packageManager` field is detected in the `package.json` file. The `package-manager-cache` input provides control over this automatic caching behavior. By default, `package-manager-cache` is set to `true`, which enables caching when a valid package manager field is detected in the `package.json` file. To disable this automatic caching, set the `package-manager-cache` input to `false`.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
@ -147,7 +147,7 @@ steps:
|
||||
package-manager-cache: false
|
||||
- run: npm ci
|
||||
```
|
||||
> If no `packageManager` or `devEngines.packageManager` field is detected in the `package.json` file, caching will remain disabled unless explicitly configured.
|
||||
> If no valid `packageManager` field is detected in the `package.json` file, caching will remain disabled unless explicitly configured.
|
||||
|
||||
The action defaults to search for the dependency file (`package-lock.json`, `npm-shrinkwrap.json` or `yarn.lock`) in the repository root, and uses its hash as a part of the cache key. Use `cache-dependency-path` for cases when multiple dependency files are used, or they are located in different subdirectories.
|
||||
|
||||
|
@ -285,28 +285,6 @@ describe('main tests', () => {
|
||||
});
|
||||
|
||||
describe('cache feature tests', () => {
|
||||
it('Should enable caching with the resolved package manager from devEngines.packageManager in package.json when the cache input is not provided', async () => {
|
||||
inputs['package-manager-cache'] = 'true';
|
||||
inputs['cache'] = ''; // No cache input is provided
|
||||
|
||||
inSpy.mockImplementation(name => inputs[name]);
|
||||
|
||||
const readFileSpy = jest.spyOn(fs, 'readFileSync');
|
||||
readFileSpy.mockImplementation(() =>
|
||||
JSON.stringify({
|
||||
devEngines: {
|
||||
packageManager: {
|
||||
name: 'pnpm'
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
await main.run();
|
||||
|
||||
expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'pnpm');
|
||||
});
|
||||
|
||||
it('Should enable caching with the resolved package manager from packageManager field in package.json when the cache input is not provided', async () => {
|
||||
inputs['package-manager-cache'] = 'true';
|
||||
inputs['cache'] = ''; // No cache input is provided
|
||||
|
20
dist/setup/index.js
vendored
20
dist/setup/index.js
vendored
@ -99683,21 +99683,17 @@ function resolveVersionInput() {
|
||||
return version;
|
||||
}
|
||||
function getNameFromPackageManagerField() {
|
||||
var _a, _b;
|
||||
// Check devEngines.packageManager and packageManager field in package.json
|
||||
// Check packageManager field in package.json
|
||||
const SUPPORTED_PACKAGE_MANAGERS = ['npm', 'yarn', 'pnpm'];
|
||||
try {
|
||||
const packageJson = JSON.parse(fs_1.default.readFileSync(path.join(process.env.GITHUB_WORKSPACE, 'package.json'), 'utf-8'));
|
||||
return (((_b = (_a = packageJson.devEngines) === null || _a === void 0 ? void 0 : _a.packageManager) === null || _b === void 0 ? void 0 : _b.name) ||
|
||||
(() => {
|
||||
const pm = packageJson.packageManager;
|
||||
if (typeof pm === 'string') {
|
||||
const regex = new RegExp(`^(?:\\^)?(${SUPPORTED_PACKAGE_MANAGERS.join('|')})@`);
|
||||
const match = pm.match(regex);
|
||||
return match ? match[1] : undefined;
|
||||
}
|
||||
return undefined;
|
||||
})());
|
||||
const pm = packageJson.packageManager;
|
||||
if (typeof pm === 'string') {
|
||||
const regex = new RegExp(`^(?:\\^)?(${SUPPORTED_PACKAGE_MANAGERS.join('|')})@`);
|
||||
const match = pm.match(regex);
|
||||
return match ? match[1] : undefined;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
catch (err) {
|
||||
return undefined;
|
||||
|
25
src/main.ts
25
src/main.ts
@ -127,7 +127,7 @@ function resolveVersionInput(): string {
|
||||
}
|
||||
|
||||
export function getNameFromPackageManagerField(): string | undefined {
|
||||
// Check devEngines.packageManager and packageManager field in package.json
|
||||
// Check packageManager field in package.json
|
||||
const SUPPORTED_PACKAGE_MANAGERS = ['npm', 'yarn', 'pnpm'];
|
||||
try {
|
||||
const packageJson = JSON.parse(
|
||||
@ -136,20 +136,15 @@ export function getNameFromPackageManagerField(): string | undefined {
|
||||
'utf-8'
|
||||
)
|
||||
);
|
||||
return (
|
||||
packageJson.devEngines?.packageManager?.name ||
|
||||
(() => {
|
||||
const pm = packageJson.packageManager;
|
||||
if (typeof pm === 'string') {
|
||||
const regex = new RegExp(
|
||||
`^(?:\\^)?(${SUPPORTED_PACKAGE_MANAGERS.join('|')})@`
|
||||
);
|
||||
const match = pm.match(regex);
|
||||
return match ? match[1] : undefined;
|
||||
}
|
||||
return undefined;
|
||||
})()
|
||||
);
|
||||
const pm = packageJson.packageManager;
|
||||
if (typeof pm === 'string') {
|
||||
const regex = new RegExp(
|
||||
`^(?:\\^)?(${SUPPORTED_PACKAGE_MANAGERS.join('|')})@`
|
||||
);
|
||||
const match = pm.match(regex);
|
||||
return match ? match[1] : undefined;
|
||||
}
|
||||
return undefined;
|
||||
} catch (err) {
|
||||
return undefined;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user