-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: inline type from
@types/node
(#233)
- Loading branch information
1 parent
c5990bc
commit cea68fd
Showing
8 changed files
with
64 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
import nodeResolve from '@rollup/plugin-node-resolve'; | ||
import typescript from '@rollup/plugin-typescript'; | ||
import builtinModules from 'builtin-modules'; | ||
import {dependencies} from './package.json'; | ||
import ts from 'rollup-plugin-ts'; | ||
import {fileURLToPath} from 'url'; | ||
import packageJson from './package.json'; | ||
|
||
export default { | ||
external: [...builtinModules, ...Object.keys(dependencies)], | ||
input: 'source/index.ts', | ||
output: [ | ||
{ | ||
dir: 'dist', | ||
entryFileNames: '[name].[format].js', | ||
format: 'cjs', | ||
sourcemap: true, | ||
}, | ||
{ | ||
dir: 'dist', | ||
entryFileNames: '[name].[format].js', | ||
format: 'es', | ||
const external = [...builtinModules, ...Object.keys(packageJson.dependencies)]; | ||
const typePath = fileURLToPath(new URL(packageJson.types, import.meta.url)); | ||
|
||
function createConfig(isEs) { | ||
return { | ||
external, | ||
input: 'source/index.ts', | ||
output: { | ||
file: isEs ? packageJson.module : packageJson.main, | ||
format: isEs ? 'es' : 'cjs', | ||
sourcemap: true, | ||
}, | ||
], | ||
plugins: [nodeResolve({extensions: ['.ts']}), typescript()], | ||
}; | ||
plugins: [ | ||
ts({ | ||
hook: { | ||
outputPath: (path, kind) => | ||
kind === 'declaration' ? typePath : path, | ||
}, | ||
tsconfig: (resolvedConfig) => | ||
isEs ? resolvedConfig : {...resolvedConfig, declaration: false}, | ||
}), | ||
], | ||
}; | ||
} | ||
|
||
export default [createConfig(false), createConfig(true)]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,22 @@ | ||
import assert from 'assert'; | ||
import {EnvironmentConfig, FileConfig} from './types'; | ||
|
||
/** | ||
* Determine whether a PropertyConfig is an EnvironmentConfig. | ||
* | ||
* @param propertyConfig - The PropertyConfig that may be an EnvironmentConfig. | ||
* @param propertyName - The name of the property. | ||
* @returns True if the PropertyConfig is an EnvironmentConfig. | ||
*/ | ||
export default function isEnvironmentConfig( | ||
propertyConfig: EnvironmentConfig<unknown> | FileConfig<unknown>, | ||
propertyName: string, | ||
): propertyConfig is EnvironmentConfig<unknown> { | ||
const isEnvironmentConfig = 'variableName' in propertyConfig; | ||
const isFileConfig = 'filePath' in propertyConfig; | ||
assert( | ||
isEnvironmentConfig || isFileConfig, | ||
`"configMap.${propertyName}" must be a string, EnvironmentConfig object, or FileConfig object. Neither "filePath" nor "variableName" are defined.`, | ||
); | ||
assert( | ||
!(isEnvironmentConfig && isFileConfig), | ||
`Cannot determine whether "configMap.${propertyName}" is an EnvironmentConfig object or a FileConfig object. Both "filePath" and "variableName" are defined.`, | ||
); | ||
if (!(isEnvironmentConfig || isFileConfig)) { | ||
throw new Error( | ||
`"configMap.${propertyName}" must be a string, EnvironmentConfig object, or FileConfig object. Neither "filePath" nor "variableName" are defined.`, | ||
); | ||
} | ||
|
||
if (isEnvironmentConfig && isFileConfig) { | ||
throw new Error( | ||
`Cannot determine whether "configMap.${propertyName}" is an EnvironmentConfig object or a FileConfig object. Both "filePath" and "variableName" are defined.`, | ||
); | ||
} | ||
|
||
return isEnvironmentConfig; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters