Leosvel Pérez Espinosa 1ea0589641
fix(angular): update broken imports in ng-packagr executors (#26319)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #26235
2024-06-03 12:28:01 +02:00

48 lines
1.3 KiB
TypeScript

/**
* Adapted from the original ng-packagr.
*
* Changes made:
* - Use our own options interface to add support for tailwindConfig.
*/
import findCacheDirectory from 'find-cache-dir';
import { InjectionToken, Provider, ValueProvider } from 'injection-js';
import { NgPackagrOptions as NgPackagrOptionsBase } from 'ng-packagr/lib/ng-package/options.di';
import { tmpdir } from 'os';
import { resolve } from 'path';
export interface NgPackagrOptions extends NgPackagrOptionsBase {
tailwindConfig?: string;
}
export const NX_OPTIONS_TOKEN = new InjectionToken<NgPackagrOptions>(
`nx.v1.options`
);
export const nxProvideOptions = (
options: NgPackagrOptions = {}
): ValueProvider => ({
provide: NX_OPTIONS_TOKEN,
useValue: normalizeOptions(options),
});
export const NX_DEFAULT_OPTIONS_PROVIDER: Provider = nxProvideOptions();
function normalizeOptions(options: NgPackagrOptions = {}) {
const ciEnv = process.env['CI'];
const isCI = ciEnv?.toLowerCase() === 'true' || ciEnv === '1';
const { cacheEnabled = !isCI, cacheDirectory = findCachePath() } = options;
return {
...options,
cacheEnabled,
cacheDirectory,
};
}
function findCachePath(): string {
const name = 'ng-packagr';
return findCacheDirectory({ name }) || resolve(tmpdir(), name);
}