postcss-load-config
Advanced tools
Comparing version 3.0.1 to 3.1.0
{ | ||
"name": "postcss-load-config", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Autoload Config for PostCSS", | ||
@@ -18,5 +18,14 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"cosmiconfig": "^7.0.0", | ||
"import-cwd": "^3.0.0" | ||
"import-cwd": "^3.0.0", | ||
"lilconfig": "^2.0.3", | ||
"yaml": "^1.10.2" | ||
}, | ||
"peerDependencies": { | ||
"ts-node": ">=9.0.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"ts-node": { | ||
"optional": true | ||
} | ||
}, | ||
"keywords": [ | ||
@@ -23,0 +32,0 @@ "postcss", |
// based on @types/postcss-load-config@2.0.1 | ||
// Type definitions for postcss-load-config 2.1 | ||
import Processor from 'postcss/lib/processor' | ||
import { Plugin, ProcessOptions, Transformer } from "postcss"; | ||
import { Options as CosmiconfigOptions } from 'cosmiconfig'; | ||
import Processor from 'postcss/lib/processor'; | ||
import { Plugin, ProcessOptions, Transformer } from 'postcss'; | ||
import { Options as ConfigOptions } from "lilconfig"; | ||
// In the ConfigContext, these three options can be instances of the | ||
// appropriate class, or strings. If they are strings, postcss-load-config will | ||
// require() them and pass the instances along. | ||
interface ProcessOptionsPreload { | ||
declare function postcssrc( | ||
ctx?: postcssrc.ConfigContext, | ||
path?: string, | ||
options?: ConfigOptions | ||
): Promise<postcssrc.Result>; | ||
declare namespace postcssrc { | ||
function sync( | ||
ctx?: ConfigContext, | ||
path?: string, | ||
options?: ConfigOptions | ||
): Result; | ||
// In the ConfigContext, these three options can be instances of the | ||
// appropriate class, or strings. If they are strings, postcss-load-config will | ||
// require() them and pass the instances along. | ||
export interface ProcessOptionsPreload { | ||
parser?: string | ProcessOptions['parser']; | ||
stringifier?: string | ProcessOptions['stringifier']; | ||
syntax?: string | ProcessOptions['syntax']; | ||
} | ||
} | ||
// The remaining ProcessOptions, sans the three above. | ||
type RemainingProcessOptions = | ||
Pick<ProcessOptions, Exclude<keyof ProcessOptions, keyof ProcessOptionsPreload>>; | ||
// The remaining ProcessOptions, sans the three above. | ||
export type RemainingProcessOptions = Pick< | ||
ProcessOptions, | ||
Exclude<keyof ProcessOptions, keyof ProcessOptionsPreload> | ||
>; | ||
// Additional context options that postcss-load-config understands. | ||
interface Context { | ||
// Additional context options that postcss-load-config understands. | ||
export interface Context { | ||
cwd?: string; | ||
env?: string; | ||
} | ||
} | ||
// The full shape of the ConfigContext. | ||
type ConfigContext = Context & ProcessOptionsPreload & RemainingProcessOptions; | ||
// The full shape of the ConfigContext. | ||
export type ConfigContext = Context & | ||
ProcessOptionsPreload & | ||
RemainingProcessOptions; | ||
// Result of postcssrc is a Promise containing the filename plus the options | ||
// and plugins that are ready to pass on to postcss. | ||
type ResultPlugin = Plugin | Transformer | Processor; | ||
// Result of postcssrc is a Promise containing the filename plus the options | ||
// and plugins that are ready to pass on to postcss. | ||
export type ResultPlugin = Plugin | Transformer | Processor; | ||
interface Result { | ||
export interface Result { | ||
file: string; | ||
options: ProcessOptions; | ||
plugins: ResultPlugin[]; | ||
} | ||
} | ||
declare function postcssrc(ctx?: ConfigContext, path?: string, options?: CosmiconfigOptions): Promise<Result>; | ||
export type ConfigPlugin = Transformer | Plugin | Processor; | ||
declare namespace postcssrc { | ||
function sync(ctx?: ConfigContext, path?: string, options?: CosmiconfigOptions): Result; | ||
export interface Config { | ||
parser?: string | ProcessOptions['parser'] | false; | ||
stringifier?: string | ProcessOptions['stringifier'] | false; | ||
syntax?: string | ProcessOptions['syntax'] | false; | ||
map?: string | false; | ||
from?: string; | ||
to?: string; | ||
plugins?: Array<ConfigPlugin | false> | Record<string, object | false>; | ||
} | ||
export type ConfigFn = (ctx: ConfigContext) => Config | Promise<Config>; | ||
} | ||
export = postcssrc; |
@@ -5,3 +5,4 @@ 'use strict' | ||
const config = require('cosmiconfig') | ||
const config = require('lilconfig') | ||
const yaml = require('yaml') | ||
@@ -11,2 +12,5 @@ const loadOptions = require('./options.js') | ||
/* istanbul ignore next */ | ||
const interopRequireDefault = (obj) => obj && obj.__esModule ? obj : { default: obj } | ||
/** | ||
@@ -22,3 +26,3 @@ * Process the result from cosmiconfig | ||
const file = result.filepath || '' | ||
let config = result.config || {} | ||
let config = interopRequireDefault(result.config).default || {} | ||
@@ -68,2 +72,55 @@ if (typeof config === 'function') { | ||
const addTypeScriptLoader = (options = {}, loader) => { | ||
const moduleName = 'postcss' | ||
return { | ||
...options, | ||
searchPlaces: [ | ||
...(options.searchPlaces || []), | ||
'package.json', | ||
`.${moduleName}rc`, | ||
`.${moduleName}rc.json`, | ||
`.${moduleName}rc.yaml`, | ||
`.${moduleName}rc.yml`, | ||
`.${moduleName}rc.ts`, | ||
`.${moduleName}rc.js`, | ||
`.${moduleName}rc.cjs`, | ||
`${moduleName}.config.ts`, | ||
`${moduleName}.config.js`, | ||
`${moduleName}.config.cjs` | ||
], | ||
loaders: { | ||
...options.loaders, | ||
'.yaml': (filepath, content) => yaml.parse(content), | ||
'.yml': (filepath, content) => yaml.parse(content), | ||
'.ts': loader | ||
} | ||
} | ||
} | ||
const withTypeScriptLoader = (rcFunc) => { | ||
return (ctx, path, options) => { | ||
return rcFunc(ctx, path, addTypeScriptLoader(options, (configFile) => { | ||
let registerer = { enabled () {} } | ||
try { | ||
// Register TypeScript compiler instance | ||
registerer = require('ts-node').register() | ||
return require(configFile) | ||
} catch (err) { | ||
if (err.code === 'MODULE_NOT_FOUND') { | ||
throw new Error( | ||
`'ts-node' is required for the TypeScript configuration files. Make sure it is installed\nError: ${err.message}` | ||
) | ||
} | ||
throw err | ||
} finally { | ||
registerer.enabled(false) | ||
} | ||
})) | ||
} | ||
} | ||
/** | ||
@@ -80,3 +137,3 @@ * Load Config | ||
*/ | ||
const rc = (ctx, path, options) => { | ||
const rc = withTypeScriptLoader((ctx, path, options) => { | ||
/** | ||
@@ -92,3 +149,3 @@ * @type {Object} The full Config Context | ||
return config.cosmiconfig('postcss', options) | ||
return config.lilconfig('postcss', options) | ||
.search(path) | ||
@@ -102,5 +159,5 @@ .then((result) => { | ||
}) | ||
} | ||
}) | ||
rc.sync = (ctx, path, options) => { | ||
rc.sync = withTypeScriptLoader((ctx, path, options) => { | ||
/** | ||
@@ -116,3 +173,3 @@ * @type {Object} The full Config Context | ||
const result = config.cosmiconfigSync('postcss', options).search(path) | ||
const result = config.lilconfigSync('postcss', options).search(path) | ||
@@ -124,3 +181,3 @@ if (!result) { | ||
return processResult(ctx, result) | ||
} | ||
}) | ||
@@ -127,0 +184,0 @@ /** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
336
21954
4
7
4
+ Addedlilconfig@^2.0.3
+ Addedyaml@^1.10.2
+ Added@cspotcode/source-map-support@0.8.1(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.9(transitive)
+ Added@tsconfig/node10@1.0.11(transitive)
+ Added@tsconfig/node12@1.0.11(transitive)
+ Added@tsconfig/node14@1.0.3(transitive)
+ Added@tsconfig/node16@1.0.4(transitive)
+ Added@types/node@22.7.4(transitive)
+ Addedacorn@8.12.1(transitive)
+ Addedacorn-walk@8.3.4(transitive)
+ Addedarg@4.1.3(transitive)
+ Addedcreate-require@1.1.1(transitive)
+ Addeddiff@4.0.2(transitive)
+ Addedlilconfig@2.1.0(transitive)
+ Addedmake-error@1.3.6(transitive)
+ Addedts-node@10.9.2(transitive)
+ Addedtypescript@5.6.2(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedv8-compile-cache-lib@3.0.1(transitive)
+ Addedyn@3.1.1(transitive)
- Removedcosmiconfig@^7.0.0
- Removed@babel/code-frame@7.24.7(transitive)
- Removed@babel/helper-validator-identifier@7.24.7(transitive)
- Removed@babel/highlight@7.24.7(transitive)
- Removed@types/parse-json@4.0.2(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedcallsites@3.1.0(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcosmiconfig@7.1.0(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedimport-fresh@3.3.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedjson-parse-even-better-errors@2.3.1(transitive)
- Removedlines-and-columns@1.2.4(transitive)
- Removedparent-module@1.0.1(transitive)
- Removedparse-json@5.2.0(transitive)
- Removedpath-type@4.0.0(transitive)
- Removedpicocolors@1.1.0(transitive)
- Removedresolve-from@4.0.0(transitive)
- Removedsupports-color@5.5.0(transitive)