@sanity/pkg-utils 5.0.8-canary.1 → 5.1.1-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks-cjs/build.cjs +22 -3
- package/dist/_chunks-cjs/build.cjs.map +1 -1
- package/dist/_chunks-cjs/check.cjs +3 -4
- package/dist/_chunks-cjs/check.cjs.map +1 -1
- package/dist/_chunks-cjs/consoleSpy.cjs +6 -9
- package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
- package/dist/_chunks-cjs/index.cjs +46 -25
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-cjs/init.cjs +1 -3
- package/dist/_chunks-cjs/init.cjs.map +1 -1
- package/dist/_chunks-cjs/watch.cjs +12 -2
- package/dist/_chunks-cjs/watch.cjs.map +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/cli.d.cts +1 -0
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +88 -45
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/node/build.ts +1 -1
- package/src/node/check.ts +4 -4
- package/src/node/core/pkg/loadPkgWithReporting.ts +7 -5
- package/src/node/core/pkg/parseExports.ts +13 -10
- package/src/node/printPackageTree.ts +0 -7
- package/src/node/resolveBuildTasks.ts +38 -2
- package/src/node/resolveWatchTasks.ts +23 -4
- package/src/node/tasks/dts/doExtract.ts +5 -5
- package/src/node/tasks/dts/dtsTask.ts +10 -6
- package/src/node/tasks/dts/dtsWatchTask.ts +10 -6
- package/src/node/tasks/dts/extractTypes.ts +26 -15
- package/src/node/tasks/dts/getTargetPaths.ts +64 -0
- package/src/node/tasks/dts/types.ts +4 -4
- package/src/node/templates/default/template.ts +0 -6
|
@@ -262,9 +262,7 @@ const RE_NAME = /^(?:@(?:[a-z0-9-*~][a-z0-9-*._~]*)\/)?[a-z0-9-~][a-z0-9-._~]*$/
|
|
|
262
262
|
}, pkgJson.bugs = {
|
|
263
263
|
url: `https://${repo.source}/${repo.owner}/${repo.name}/issues`
|
|
264
264
|
}, pkgJson.homepage = `https://${repo.source}/${repo.owner}/${repo.name}#readme`), features.typescript) {
|
|
265
|
-
pkgJson.types = "./dist/index.d.ts"
|
|
266
|
-
const mainExport = pkgJson.exports?.["."];
|
|
267
|
-
logger.isRecord(mainExport) && (mainExport.types = "./dist/index.d.ts"), pkgJson.scripts = {
|
|
265
|
+
pkgJson.types = "./dist/index.d.ts", pkgJson.scripts = {
|
|
268
266
|
...pkgJson.scripts,
|
|
269
267
|
"ts:check": "tsc --build"
|
|
270
268
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.cjs","sources":["../../src/node/core/template/createFromTemplate.ts","../../src/node/core/template/define.ts","../../src/node/isEmptyDirectory.ts","../../src/node/templates/default/template.ts","../../src/node/init.ts"],"sourcesContent":["import {writeFile} from 'fs/promises'\nimport {mkdirp} from 'mkdirp'\nimport {dirname, relative, resolve} from 'path'\nimport prompts from 'prompts'\n\nimport {Logger} from '../../logger'\nimport {PkgTemplate} from './types'\n\nconst promptsTypes = {\n string: 'text' as const,\n}\n\n/** @internal */\nexport async function createFromTemplate(options: {\n cwd: string\n logger: Logger\n packagePath: string\n template: PkgTemplate\n}): Promise<void> {\n const {cwd, logger, packagePath, template: templateOrResolver} = options\n\n const template =\n typeof templateOrResolver === 'function'\n ? await templateOrResolver({cwd, logger, packagePath})\n : templateOrResolver\n\n logger.log('create new package at', relative(cwd, packagePath))\n\n const templateOptions: Record<string, string> = {}\n\n for (const templateOption of template.options) {\n const templateValidate = templateOption.validate\n\n const res = await prompts(\n {\n type: promptsTypes[templateOption.type],\n name: templateOption.name,\n message: templateOption.description,\n validate: templateValidate ? (prev) => templateValidate(prev) : undefined,\n initial:\n typeof templateOption.initial === 'function'\n ? templateOption.initial(templateOptions)\n : templateOption.initial,\n },\n {onCancel: () => process.exit(0)},\n )\n\n templateOptions[templateOption.name] = templateOption.parse\n ? templateOption.parse(res[templateOption.name])\n : res[templateOption.name]\n }\n\n const features: Record<string, boolean> = {}\n\n for (const templateFeature of template.features) {\n const res = templateFeature.optional\n ? await prompts(\n {\n type: 'confirm',\n name: 'confirm',\n message: `use ${templateFeature.name}?`,\n initial: templateFeature.initial,\n },\n {onCancel: () => process.exit(0)},\n )\n : undefined\n\n features[templateFeature.name] = res?.confirm || !templateFeature.optional\n }\n\n const files = await template.getFiles(templateOptions, features)\n\n files.sort((a, b) => {\n return a.name.localeCompare(b.name)\n })\n\n for (const file of files) {\n const filePath = resolve(packagePath, file.name)\n\n await mkdirp(dirname(filePath))\n await writeFile(filePath, file.contents.trim() + '\\n')\n\n logger.success(`wrote ${relative(cwd, filePath)}`)\n }\n}\n","import {PkgTemplateOption} from './types'\n\n/** @public */\nexport function defineTemplateOption<T>(option: PkgTemplateOption<T>): PkgTemplateOption<T> {\n return option\n}\n","import {readdir} from 'fs/promises'\n\nexport async function isEmptyDirectory(dirPath: string): Promise<boolean> {\n return (await readdir(dirPath)).length === 0\n}\n","import getLatestVersion from 'get-latest-version'\nimport gitUrlParse from 'git-url-parse'\nimport {outdent} from 'outdent'\nimport parseGitConfig from 'parse-git-config'\nimport {resolve} from 'path'\nimport prettier, {Config as PrettierConfig} from 'prettier'\n\nimport {defineTemplateOption, isRecord, PackageJSON, PkgTemplate, PkgTemplateFile} from '../../core'\n\nconst RE_NAME = /^(?:@(?:[a-z0-9-*~][a-z0-9-*._~]*)\\/)?[a-z0-9-~][a-z0-9-._~]*$/i\n\nexport const defaultTemplate: PkgTemplate = async ({cwd, logger, packagePath}) => {\n const gitConfig = await parseGitConfig({cwd, type: 'global'})\n\n return {\n options: [\n defineTemplateOption<{owner: string; name: string}>({\n name: 'repo',\n type: 'string',\n description: 'git url',\n validate: (v) => {\n if (!v) return true\n\n try {\n gitUrlParse(v)\n\n return true\n } catch (err) {\n return 'invalid git url'\n }\n },\n parse: (v) => {\n if (!v) return null\n\n const result = gitUrlParse(v)\n\n return {source: result.source, owner: result.owner, name: result.name}\n },\n }),\n defineTemplateOption({\n name: 'pkgName',\n type: 'string',\n description: 'package name',\n initial: (options) => options.repo?.name || undefined,\n validate: (v) => {\n if (!v) return 'package name is required'\n\n const match = RE_NAME.exec(v)\n\n if (!match) {\n return 'invalid package name'\n }\n\n return true\n },\n parse: (v) => {\n if (!v) {\n throw new Error('package name is required')\n }\n\n const match = RE_NAME.exec(v)\n\n if (!match) {\n throw new Error('invalid package name')\n }\n\n const [scope, name] = v.split('/')\n\n return {scope, name, fullName: v}\n },\n }),\n defineTemplateOption({\n name: 'description',\n type: 'string',\n description: 'package description',\n }),\n defineTemplateOption({\n name: 'authorName',\n type: 'string',\n description: 'package author name',\n initial: gitConfig?.user?.name,\n }),\n defineTemplateOption({\n name: 'authorEmail',\n type: 'string',\n description: 'package author email',\n initial: gitConfig?.user?.email,\n }),\n defineTemplateOption({\n name: 'license',\n type: 'string',\n description: 'package license',\n initial: 'MIT',\n validate: (v) => {\n if (!v) return 'license is required'\n\n return true\n },\n }),\n ],\n\n features: [\n {\n name: 'eslint',\n optional: true,\n initial: true,\n },\n {\n name: 'prettier',\n optional: true,\n initial: true,\n },\n {\n name: 'typescript',\n optional: true,\n initial: true,\n },\n ],\n\n async getFiles(options, features) {\n const {pkgName, repo} = options\n const {fullName: name} = pkgName\n\n const author =\n [options.authorName, options.authorEmail && `<${options.authorEmail}>`]\n .filter(Boolean)\n .join(' ') ?? undefined\n\n const prettierConfig: PrettierConfig | undefined = features.prettier\n ? {\n bracketSpacing: false,\n plugins: ['prettier-plugin-packagejson'],\n printWidth: 100,\n quoteProps: 'consistent',\n semi: false,\n singleQuote: true,\n tabWidth: 2,\n overrides: [\n {\n files: ['*.yml'],\n options: {\n singleQuote: false,\n },\n },\n ],\n }\n : undefined\n\n const pkgJson: PackageJSON & {\n prettier?: PrettierConfig\n ['lint-staged']?: Record<string, string[]>\n } = {\n name,\n 'version': '0.0.0',\n 'description': options.description ?? undefined,\n 'keywords': [],\n 'homepage': undefined,\n 'bugs': undefined,\n 'repository': undefined,\n 'license': options.license,\n author,\n 'sideEffects': false,\n 'type': 'module',\n 'exports': {\n '.': {\n types: undefined,\n source: features.typescript ? './src/index.ts' : './src/index.js',\n import: './dist/index.js',\n require: './dist/index.cjs',\n default: './dist/index.js',\n },\n './package.json': './package.json',\n },\n 'main': './dist/index.cjs',\n 'module': './dist/index.js',\n 'source': features.typescript ? './src/index.ts' : './src/index.js',\n 'types': undefined,\n 'files': ['dist', 'src'],\n 'scripts': {\n 'build': 'run-s clean pkg:build pkg:check',\n 'clean': 'rimraf dist',\n 'format': features.prettier ? 'prettier --write --cache --ignore-unknown .' : undefined,\n 'pkg:build': 'pkg build --strict',\n 'pkg:check': 'pkg check --strict',\n },\n 'lint-staged': features.prettier\n ? {\n '*': ['prettier --write --cache --ignore-unknown'],\n }\n : undefined,\n // prettier: prettierConfig,\n 'browserslist': 'extends @sanity/browserslist-config',\n 'dependencies': {},\n 'devDependencies': {\n '@sanity/pkg-utils': '*',\n '@typescript-eslint/eslint-plugin': undefined,\n '@typescript-eslint/parser': undefined,\n 'eslint': undefined,\n 'eslint-config-prettier': undefined,\n 'eslint-plugin-import': undefined,\n 'eslint-plugin-prettier': undefined,\n 'eslint-plugin-simple-import-sort': undefined,\n 'lint-staged': '*',\n 'npm-run-all': '*',\n 'prettier': features.prettier ? '*' : undefined,\n 'prettier-plugin-packagejson': features.prettier ? '*' : undefined,\n 'rimraf': '*',\n 'typescript': undefined,\n },\n 'engines': {\n node: '>=18.0.0',\n },\n }\n\n const files: PkgTemplateFile[] = []\n\n // .editorconfig\n files.push({\n name: '.editorconfig',\n contents: outdent`\n root = true\n\n [*]\n charset = utf-8\n indent_style = space\n indent_size = 2\n end_of_line = lf\n insert_final_newline = true\n trim_trailing_whitespace = true\n `,\n })\n\n // .gitignore\n files.push({\n name: '.gitignore',\n contents: outdent`\n *.local\n *.log\n *.tgz\n\n .DS_Store\n dist\n etc\n node_modules\n `,\n })\n\n if (features.prettier) {\n files.push({\n name: '.prettierignore',\n contents: outdent`\n dist\n pnpm-lock.yaml\n `,\n })\n\n files.push({\n name: '.prettierrc',\n contents: await format(\n resolve(packagePath, '.prettierrc.json'),\n JSON.stringify(prettierConfig, null, 2) + '\\n',\n prettierConfig,\n ),\n })\n }\n\n if (repo) {\n pkgJson.repository = {\n type: 'git',\n url: `git+ssh://git@${repo.source}/${repo.owner}/${repo.name}.git`,\n }\n pkgJson.bugs = {\n url: `https://${repo.source}/${repo.owner}/${repo.name}/issues`,\n }\n pkgJson.homepage = `https://${repo.source}/${repo.owner}/${repo.name}#readme`\n }\n\n if (features.typescript) {\n pkgJson.types = './dist/index.d.ts'\n\n const mainExport = pkgJson.exports?.['.']\n\n if (isRecord(mainExport)) {\n mainExport.types = './dist/index.d.ts'\n }\n\n pkgJson.scripts = {\n ...pkgJson.scripts,\n ['ts:check']: 'tsc --build',\n }\n\n const devDependencies = pkgJson.devDependencies\n\n if (isRecord(devDependencies)) {\n devDependencies['typescript'] = '*'\n }\n }\n\n if (features.eslint) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const eslintConfig: any = {\n root: true,\n env: {\n browser: true,\n es6: true,\n node: true,\n },\n extends: [\n 'eslint:recommended',\n features.prettier ? 'plugin:prettier/recommended' : undefined,\n ].filter(Boolean),\n parserOptions: {\n ecmaVersion: 2020,\n sourceType: 'module',\n },\n plugins: [\n 'import',\n 'simple-import-sort',\n features.prettier ? 'prettier' : undefined,\n ].filter(Boolean),\n rules: {\n 'no-console': 'error',\n 'no-shadow': 'error',\n 'no-warning-comments': ['warn', {location: 'start', terms: ['todo', 'fixme']}],\n 'quote-props': ['warn', 'consistent-as-needed'],\n 'simple-import-sort/exports': 'warn',\n 'simple-import-sort/imports': 'warn',\n 'strict': ['warn', 'global'],\n },\n }\n\n files.push({\n name: '.eslintignore',\n contents: outdent`\n dist\n `,\n })\n\n pkgJson.scripts = {\n ...pkgJson.scripts,\n lint: features.typescript\n ? 'eslint . --ext .cjs,.js,.ts,.tsx'\n : 'eslint . --ext .cjs,.js',\n }\n\n pkgJson.devDependencies = {\n ...pkgJson.devDependencies,\n 'eslint': '*',\n 'eslint-config-prettier': features.prettier ? '*' : undefined,\n 'eslint-plugin-simple-import-sort': '*',\n 'eslint-plugin-import': '*',\n 'eslint-plugin-prettier': features.prettier ? '*' : undefined,\n }\n\n if (features.typescript) {\n pkgJson.devDependencies = {\n ...pkgJson.devDependencies,\n '@typescript-eslint/eslint-plugin': '*',\n '@typescript-eslint/parser': '*',\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const eslintConfigOverride: any = {\n files: ['**/*.ts', '**/*.tsx'],\n parser: '@typescript-eslint/parser',\n parserOptions: {\n project: ['./tsconfig.json'],\n },\n extends: [\n 'eslint:recommended',\n features.prettier ? 'plugin:prettier/recommended' : undefined,\n 'plugin:@typescript-eslint/eslint-recommended',\n 'plugin:@typescript-eslint/recommended',\n ].filter(Boolean),\n plugins: [\n 'import',\n '@typescript-eslint',\n 'simple-import-sort',\n features.prettier ? 'prettier' : undefined,\n ].filter(Boolean),\n rules: {\n '@typescript-eslint/explicit-module-boundary-types': 'error',\n '@typescript-eslint/interface-name-prefix': 'off',\n '@typescript-eslint/member-delimiter-style': 'off',\n '@typescript-eslint/no-empty-interface': 'off',\n },\n }\n\n eslintConfig.overrides = [eslintConfigOverride]\n }\n\n files.push({\n name: '.eslintrc.cjs',\n contents: await format(\n resolve(packagePath, '.eslintrc.cjs'),\n outdent`\n 'use strict'\n\n /** @type import('eslint').Linter.Config */\n module.exports = ${JSON.stringify(eslintConfig, null, 2)}\n `,\n prettierConfig,\n ),\n })\n }\n\n if (features.typescript) {\n files.push({\n name: 'tsconfig.settings.json',\n contents: await format(\n resolve(packagePath, 'tsconfig.settings.json'),\n outdent`\n {\n \"compilerOptions\": {\n // Completeness\n \"skipLibCheck\": true,\n\n // Interop constraints\n \"allowSyntheticDefaultImports\": true,\n \"esModuleInterop\": true,\n\n // Language and environment\n \"target\": \"ES2020\",\n\n // Modules\n \"module\": \"ES2020\",\n \"moduleResolution\": \"Node\",\n\n // Type checking\n \"alwaysStrict\": true,\n \"noFallthroughCasesInSwitch\": true,\n \"noImplicitAny\": true,\n \"noImplicitReturns\": true,\n \"noImplicitThis\": true,\n \"noUnusedLocals\": true,\n \"noUnusedParameters\": true,\n \"strict\": true,\n \"strictFunctionTypes\": true,\n \"strictNullChecks\": true,\n \"strictPropertyInitialization\": true\n }\n }\n `,\n prettierConfig,\n ),\n })\n\n files.push({\n name: 'tsconfig.dist.json',\n contents: await format(\n resolve(packagePath, 'tsconfig.dist.json'),\n outdent`\n {\n \"extends\": \"./tsconfig.settings\",\n \"include\": [\"./src\"],\n \"exclude\": [\"./src/**/*.test.ts\"],\n \"compilerOptions\": {\n \"rootDir\": \".\",\n \"outDir\": \"./dist\",\n \"resolveJsonModule\": true\n }\n }\n `,\n prettierConfig,\n ),\n })\n\n files.push({\n name: 'tsconfig.json',\n contents: await format(\n resolve(packagePath, 'tsconfig.json'),\n outdent`\n {\n \"extends\": \"./tsconfig.settings\",\n \"include\": [\"./**/*.cjs\", \"./**/*.ts\", \"./**/*.tsx\"],\n \"exclude\": [\"./node_modules\"],\n \"compilerOptions\": {\n \"rootDir\": \".\",\n \"outDir\": \"./dist\",\n \"noEmit\": true,\n \"allowJs\": true,\n \"resolveJsonModule\": true,\n }\n }\n `,\n prettierConfig,\n ),\n })\n }\n\n // source file\n if (features.typescript) {\n files.push({\n name: 'package.config.ts',\n contents: await format(\n resolve(packagePath, 'package.config.ts'),\n outdent`\n import {defineConfig} from '@sanity/pkg-utils'\n\n // https://github.com/sanity-io/pkg-utils#configuration\n export default defineConfig({\n // the path to the tsconfig file for distributed builds\n tsconfig: 'tsconfig.dist.json',\n })\n `,\n prettierConfig,\n ),\n })\n\n files.push({\n name: 'src/index.ts',\n contents: await format(\n resolve(packagePath, 'src/index.ts'),\n outdent`\n /** @public */\n export function main(): void {\n //\n }\n `,\n prettierConfig,\n ),\n })\n } else {\n files.push({\n name: 'package.config.js',\n contents: await format(\n resolve(packagePath, 'package.config.js'),\n outdent`\n import {defineConfig} from '@sanity/pkg-utils'\n\n export default defineConfig({\n extract: {\n rules: {\n // do not require internal members to be prefixed with \\`_\\`\n 'ae-internal-missing-underscore': 'off',\n },\n },\n })\n `,\n prettierConfig,\n ),\n })\n\n files.push({\n name: 'src/index.js',\n contents: await format(\n resolve(packagePath, 'src/index.js'),\n outdent`\n /** @public */\n export function main() {\n //\n }\n `,\n prettierConfig,\n ),\n })\n }\n\n // Resolve latest dependencies\n try {\n pkgJson.dependencies = await resolveLatestDeps(pkgJson.dependencies ?? {})\n } catch (error) {\n logger.warn(error instanceof Error ? error.message : error)\n }\n\n // Resolve latest devDependencies\n try {\n pkgJson.devDependencies = await resolveLatestDeps(pkgJson.devDependencies ?? {})\n } catch (error) {\n logger.warn(error instanceof Error ? error.message : error)\n }\n\n files.push({\n name: 'package.json',\n contents: await format(\n resolve(packagePath, 'package.json'),\n JSON.stringify(pkgJson, null, 2),\n prettierConfig,\n ),\n })\n\n return files\n },\n }\n}\n\nfunction format(filepath: string, input: string, prettierOptions: PrettierConfig | undefined) {\n return prettier.format(input, {...prettierOptions, plugins: [], filepath})\n}\n\nasync function resolveLatestDeps(deps: Record<string, string | undefined>) {\n const depsEntries = Object.entries(deps)\n const latestDeps: Record<string, string> = {}\n\n for (const entry of depsEntries) {\n const [name, version] = entry\n\n if (version) {\n const latestVersion = await getLatestVersion(name, version)\n\n latestDeps[name] = latestVersion ? `^${latestVersion}` : version\n }\n }\n\n return latestDeps\n}\n","import {lstat} from 'fs/promises'\nimport {mkdirp} from 'mkdirp'\nimport {resolve} from 'path'\n\nimport {createFromTemplate} from './core/template'\nimport {fileExists} from './fileExists'\nimport {isEmptyDirectory} from './isEmptyDirectory'\nimport {createLogger} from './logger'\nimport {defaultTemplate} from './templates'\n\n/** @public */\nexport async function init(options: {cwd: string; path: string}): Promise<void> {\n if (!options.cwd) {\n throw new Error('Missing required option: cwd')\n }\n\n if (!options.path) {\n throw new Error('Missing required option: path')\n }\n\n const logger = createLogger()\n\n const packagePath = resolve(options.cwd, options.path)\n\n await ensurePackagePath(packagePath)\n\n await createFromTemplate({\n cwd: options.cwd,\n logger,\n template: defaultTemplate,\n packagePath,\n })\n}\n\nasync function ensurePackagePath(packagePath: string): Promise<void> {\n const exists = fileExists(packagePath)\n\n if (!exists) {\n await mkdirp(packagePath)\n\n return\n }\n\n const dir = (await lstat(packagePath)).isDirectory()\n\n if (!dir) {\n throw new Error('the package path is a file, not a directory')\n }\n\n const empty = await isEmptyDirectory(packagePath)\n\n if (!empty) {\n throw new Error('the package directory is not empty')\n }\n}\n"],"names":["logger","relative","prompts","resolve","mkdirp","dirname","writeFile","readdir","parseGitConfig","gitUrlParse","outdent","isRecord","prettier","getLatestVersion","createLogger","fileExists","lstat"],"mappings":";;;;;;;;;;;;;;AAQA,MAAM,eAAe;AAAA,EACnB,QAAQ;AACV;AAGA,eAAsB,mBAAmB,SAKvB;AAChB,QAAM,EAAC,KAAK,QAAAA,SAAQ,aAAa,UAAU,mBAAA,IAAsB,SAE3D,WACJ,OAAO,sBAAuB,aAC1B,MAAM,mBAAmB,EAAC,KAAK,QAAAA,SAAQ,YAAA,CAAY,IACnD;AAEN,EAAAA,QAAO,IAAI,yBAAyBC,KAAS,SAAA,KAAK,WAAW,CAAC;AAE9D,QAAM,kBAA0C,CAAA;AAErC,aAAA,kBAAkB,SAAS,SAAS;AAC7C,UAAM,mBAAmB,eAAe,UAElC,MAAM,MAAMC,iBAAA;AAAA,MAChB;AAAA,QACE,MAAM,aAAa,eAAe,IAAI;AAAA,QACtC,MAAM,eAAe;AAAA,QACrB,SAAS,eAAe;AAAA,QACxB,UAAU,mBAAmB,CAAC,SAAS,iBAAiB,IAAI,IAAI;AAAA,QAChE,SACE,OAAO,eAAe,WAAY,aAC9B,eAAe,QAAQ,eAAe,IACtC,eAAe;AAAA,MACvB;AAAA,MACA,EAAC,UAAU,MAAM,QA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AAAb,WAASc,oBAET,GAAA,cAAcX,KAAAA,QAAQ,QAAQ,KAAK,QAAQ,IAAI;AAErD,QAAM,kBAAkB,WAAW,GAEnC,MAAM,mBAAmB;AAAA,IACvB,KAAK,QAAQ;AAAA,IAAA,QACbH;AAAAA,IACA,UAAU;AAAA,IACV;AAAA,EAAA,CACD;AACH;AAEA,eAAe,kBAAkB,aAAoC;AAG/D,MAAA,CAFWe,OAAAA,WAAW,WAAW,GAExB;AACX,UAAMX,OAAAA,OAAO,WAAW;AAExB;AAAA,EACF;AAIA,MAAI,EAFS,MAAMY,GAAAA,MAAM,WAAW,GAAG,YAAY;AAG3C,UAAA,IAAI,MAAM,6CAA6C;AAK3D,MAAA,CAFU,MAAM,iBAAiB,WAAW;AAGxC,UAAA,IAAI,MAAM,oCAAoC;AAExD;;;;"}
|
|
1
|
+
{"version":3,"file":"init.cjs","sources":["../../src/node/core/template/createFromTemplate.ts","../../src/node/core/template/define.ts","../../src/node/isEmptyDirectory.ts","../../src/node/templates/default/template.ts","../../src/node/init.ts"],"sourcesContent":["import {writeFile} from 'fs/promises'\nimport {mkdirp} from 'mkdirp'\nimport {dirname, relative, resolve} from 'path'\nimport prompts from 'prompts'\n\nimport {Logger} from '../../logger'\nimport {PkgTemplate} from './types'\n\nconst promptsTypes = {\n string: 'text' as const,\n}\n\n/** @internal */\nexport async function createFromTemplate(options: {\n cwd: string\n logger: Logger\n packagePath: string\n template: PkgTemplate\n}): Promise<void> {\n const {cwd, logger, packagePath, template: templateOrResolver} = options\n\n const template =\n typeof templateOrResolver === 'function'\n ? await templateOrResolver({cwd, logger, packagePath})\n : templateOrResolver\n\n logger.log('create new package at', relative(cwd, packagePath))\n\n const templateOptions: Record<string, string> = {}\n\n for (const templateOption of template.options) {\n const templateValidate = templateOption.validate\n\n const res = await prompts(\n {\n type: promptsTypes[templateOption.type],\n name: templateOption.name,\n message: templateOption.description,\n validate: templateValidate ? (prev) => templateValidate(prev) : undefined,\n initial:\n typeof templateOption.initial === 'function'\n ? templateOption.initial(templateOptions)\n : templateOption.initial,\n },\n {onCancel: () => process.exit(0)},\n )\n\n templateOptions[templateOption.name] = templateOption.parse\n ? templateOption.parse(res[templateOption.name])\n : res[templateOption.name]\n }\n\n const features: Record<string, boolean> = {}\n\n for (const templateFeature of template.features) {\n const res = templateFeature.optional\n ? await prompts(\n {\n type: 'confirm',\n name: 'confirm',\n message: `use ${templateFeature.name}?`,\n initial: templateFeature.initial,\n },\n {onCancel: () => process.exit(0)},\n )\n : undefined\n\n features[templateFeature.name] = res?.confirm || !templateFeature.optional\n }\n\n const files = await template.getFiles(templateOptions, features)\n\n files.sort((a, b) => {\n return a.name.localeCompare(b.name)\n })\n\n for (const file of files) {\n const filePath = resolve(packagePath, file.name)\n\n await mkdirp(dirname(filePath))\n await writeFile(filePath, file.contents.trim() + '\\n')\n\n logger.success(`wrote ${relative(cwd, filePath)}`)\n }\n}\n","import {PkgTemplateOption} from './types'\n\n/** @public */\nexport function defineTemplateOption<T>(option: PkgTemplateOption<T>): PkgTemplateOption<T> {\n return option\n}\n","import {readdir} from 'fs/promises'\n\nexport async function isEmptyDirectory(dirPath: string): Promise<boolean> {\n return (await readdir(dirPath)).length === 0\n}\n","import getLatestVersion from 'get-latest-version'\nimport gitUrlParse from 'git-url-parse'\nimport {outdent} from 'outdent'\nimport parseGitConfig from 'parse-git-config'\nimport {resolve} from 'path'\nimport prettier, {Config as PrettierConfig} from 'prettier'\n\nimport {defineTemplateOption, isRecord, PackageJSON, PkgTemplate, PkgTemplateFile} from '../../core'\n\nconst RE_NAME = /^(?:@(?:[a-z0-9-*~][a-z0-9-*._~]*)\\/)?[a-z0-9-~][a-z0-9-._~]*$/i\n\nexport const defaultTemplate: PkgTemplate = async ({cwd, logger, packagePath}) => {\n const gitConfig = await parseGitConfig({cwd, type: 'global'})\n\n return {\n options: [\n defineTemplateOption<{owner: string; name: string}>({\n name: 'repo',\n type: 'string',\n description: 'git url',\n validate: (v) => {\n if (!v) return true\n\n try {\n gitUrlParse(v)\n\n return true\n } catch (err) {\n return 'invalid git url'\n }\n },\n parse: (v) => {\n if (!v) return null\n\n const result = gitUrlParse(v)\n\n return {source: result.source, owner: result.owner, name: result.name}\n },\n }),\n defineTemplateOption({\n name: 'pkgName',\n type: 'string',\n description: 'package name',\n initial: (options) => options.repo?.name || undefined,\n validate: (v) => {\n if (!v) return 'package name is required'\n\n const match = RE_NAME.exec(v)\n\n if (!match) {\n return 'invalid package name'\n }\n\n return true\n },\n parse: (v) => {\n if (!v) {\n throw new Error('package name is required')\n }\n\n const match = RE_NAME.exec(v)\n\n if (!match) {\n throw new Error('invalid package name')\n }\n\n const [scope, name] = v.split('/')\n\n return {scope, name, fullName: v}\n },\n }),\n defineTemplateOption({\n name: 'description',\n type: 'string',\n description: 'package description',\n }),\n defineTemplateOption({\n name: 'authorName',\n type: 'string',\n description: 'package author name',\n initial: gitConfig?.user?.name,\n }),\n defineTemplateOption({\n name: 'authorEmail',\n type: 'string',\n description: 'package author email',\n initial: gitConfig?.user?.email,\n }),\n defineTemplateOption({\n name: 'license',\n type: 'string',\n description: 'package license',\n initial: 'MIT',\n validate: (v) => {\n if (!v) return 'license is required'\n\n return true\n },\n }),\n ],\n\n features: [\n {\n name: 'eslint',\n optional: true,\n initial: true,\n },\n {\n name: 'prettier',\n optional: true,\n initial: true,\n },\n {\n name: 'typescript',\n optional: true,\n initial: true,\n },\n ],\n\n async getFiles(options, features) {\n const {pkgName, repo} = options\n const {fullName: name} = pkgName\n\n const author =\n [options.authorName, options.authorEmail && `<${options.authorEmail}>`]\n .filter(Boolean)\n .join(' ') ?? undefined\n\n const prettierConfig: PrettierConfig | undefined = features.prettier\n ? {\n bracketSpacing: false,\n plugins: ['prettier-plugin-packagejson'],\n printWidth: 100,\n quoteProps: 'consistent',\n semi: false,\n singleQuote: true,\n tabWidth: 2,\n overrides: [\n {\n files: ['*.yml'],\n options: {\n singleQuote: false,\n },\n },\n ],\n }\n : undefined\n\n const pkgJson: PackageJSON & {\n prettier?: PrettierConfig\n ['lint-staged']?: Record<string, string[]>\n } = {\n name,\n 'version': '0.0.0',\n 'description': options.description ?? undefined,\n 'keywords': [],\n 'homepage': undefined,\n 'bugs': undefined,\n 'repository': undefined,\n 'license': options.license,\n author,\n 'sideEffects': false,\n 'type': 'module',\n 'exports': {\n '.': {\n types: undefined,\n source: features.typescript ? './src/index.ts' : './src/index.js',\n import: './dist/index.js',\n require: './dist/index.cjs',\n default: './dist/index.js',\n },\n './package.json': './package.json',\n },\n 'main': './dist/index.cjs',\n 'module': './dist/index.js',\n 'source': features.typescript ? './src/index.ts' : './src/index.js',\n 'types': undefined,\n 'files': ['dist', 'src'],\n 'scripts': {\n 'build': 'run-s clean pkg:build pkg:check',\n 'clean': 'rimraf dist',\n 'format': features.prettier ? 'prettier --write --cache --ignore-unknown .' : undefined,\n 'pkg:build': 'pkg build --strict',\n 'pkg:check': 'pkg check --strict',\n },\n 'lint-staged': features.prettier\n ? {\n '*': ['prettier --write --cache --ignore-unknown'],\n }\n : undefined,\n // prettier: prettierConfig,\n 'browserslist': 'extends @sanity/browserslist-config',\n 'dependencies': {},\n 'devDependencies': {\n '@sanity/pkg-utils': '*',\n '@typescript-eslint/eslint-plugin': undefined,\n '@typescript-eslint/parser': undefined,\n 'eslint': undefined,\n 'eslint-config-prettier': undefined,\n 'eslint-plugin-import': undefined,\n 'eslint-plugin-prettier': undefined,\n 'eslint-plugin-simple-import-sort': undefined,\n 'lint-staged': '*',\n 'npm-run-all': '*',\n 'prettier': features.prettier ? '*' : undefined,\n 'prettier-plugin-packagejson': features.prettier ? '*' : undefined,\n 'rimraf': '*',\n 'typescript': undefined,\n },\n 'engines': {\n node: '>=18.0.0',\n },\n }\n\n const files: PkgTemplateFile[] = []\n\n // .editorconfig\n files.push({\n name: '.editorconfig',\n contents: outdent`\n root = true\n\n [*]\n charset = utf-8\n indent_style = space\n indent_size = 2\n end_of_line = lf\n insert_final_newline = true\n trim_trailing_whitespace = true\n `,\n })\n\n // .gitignore\n files.push({\n name: '.gitignore',\n contents: outdent`\n *.local\n *.log\n *.tgz\n\n .DS_Store\n dist\n etc\n node_modules\n `,\n })\n\n if (features.prettier) {\n files.push({\n name: '.prettierignore',\n contents: outdent`\n dist\n pnpm-lock.yaml\n `,\n })\n\n files.push({\n name: '.prettierrc',\n contents: await format(\n resolve(packagePath, '.prettierrc.json'),\n JSON.stringify(prettierConfig, null, 2) + '\\n',\n prettierConfig,\n ),\n })\n }\n\n if (repo) {\n pkgJson.repository = {\n type: 'git',\n url: `git+ssh://git@${repo.source}/${repo.owner}/${repo.name}.git`,\n }\n pkgJson.bugs = {\n url: `https://${repo.source}/${repo.owner}/${repo.name}/issues`,\n }\n pkgJson.homepage = `https://${repo.source}/${repo.owner}/${repo.name}#readme`\n }\n\n if (features.typescript) {\n pkgJson.types = './dist/index.d.ts'\n\n pkgJson.scripts = {\n ...pkgJson.scripts,\n ['ts:check']: 'tsc --build',\n }\n\n const devDependencies = pkgJson.devDependencies\n\n if (isRecord(devDependencies)) {\n devDependencies['typescript'] = '*'\n }\n }\n\n if (features.eslint) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const eslintConfig: any = {\n root: true,\n env: {\n browser: true,\n es6: true,\n node: true,\n },\n extends: [\n 'eslint:recommended',\n features.prettier ? 'plugin:prettier/recommended' : undefined,\n ].filter(Boolean),\n parserOptions: {\n ecmaVersion: 2020,\n sourceType: 'module',\n },\n plugins: [\n 'import',\n 'simple-import-sort',\n features.prettier ? 'prettier' : undefined,\n ].filter(Boolean),\n rules: {\n 'no-console': 'error',\n 'no-shadow': 'error',\n 'no-warning-comments': ['warn', {location: 'start', terms: ['todo', 'fixme']}],\n 'quote-props': ['warn', 'consistent-as-needed'],\n 'simple-import-sort/exports': 'warn',\n 'simple-import-sort/imports': 'warn',\n 'strict': ['warn', 'global'],\n },\n }\n\n files.push({\n name: '.eslintignore',\n contents: outdent`\n dist\n `,\n })\n\n pkgJson.scripts = {\n ...pkgJson.scripts,\n lint: features.typescript\n ? 'eslint . --ext .cjs,.js,.ts,.tsx'\n : 'eslint . --ext .cjs,.js',\n }\n\n pkgJson.devDependencies = {\n ...pkgJson.devDependencies,\n 'eslint': '*',\n 'eslint-config-prettier': features.prettier ? '*' : undefined,\n 'eslint-plugin-simple-import-sort': '*',\n 'eslint-plugin-import': '*',\n 'eslint-plugin-prettier': features.prettier ? '*' : undefined,\n }\n\n if (features.typescript) {\n pkgJson.devDependencies = {\n ...pkgJson.devDependencies,\n '@typescript-eslint/eslint-plugin': '*',\n '@typescript-eslint/parser': '*',\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const eslintConfigOverride: any = {\n files: ['**/*.ts', '**/*.tsx'],\n parser: '@typescript-eslint/parser',\n parserOptions: {\n project: ['./tsconfig.json'],\n },\n extends: [\n 'eslint:recommended',\n features.prettier ? 'plugin:prettier/recommended' : undefined,\n 'plugin:@typescript-eslint/eslint-recommended',\n 'plugin:@typescript-eslint/recommended',\n ].filter(Boolean),\n plugins: [\n 'import',\n '@typescript-eslint',\n 'simple-import-sort',\n features.prettier ? 'prettier' : undefined,\n ].filter(Boolean),\n rules: {\n '@typescript-eslint/explicit-module-boundary-types': 'error',\n '@typescript-eslint/interface-name-prefix': 'off',\n '@typescript-eslint/member-delimiter-style': 'off',\n '@typescript-eslint/no-empty-interface': 'off',\n },\n }\n\n eslintConfig.overrides = [eslintConfigOverride]\n }\n\n files.push({\n name: '.eslintrc.cjs',\n contents: await format(\n resolve(packagePath, '.eslintrc.cjs'),\n outdent`\n 'use strict'\n\n /** @type import('eslint').Linter.Config */\n module.exports = ${JSON.stringify(eslintConfig, null, 2)}\n `,\n prettierConfig,\n ),\n })\n }\n\n if (features.typescript) {\n files.push({\n name: 'tsconfig.settings.json',\n contents: await format(\n resolve(packagePath, 'tsconfig.settings.json'),\n outdent`\n {\n \"compilerOptions\": {\n // Completeness\n \"skipLibCheck\": true,\n\n // Interop constraints\n \"allowSyntheticDefaultImports\": true,\n \"esModuleInterop\": true,\n\n // Language and environment\n \"target\": \"ES2020\",\n\n // Modules\n \"module\": \"ES2020\",\n \"moduleResolution\": \"Node\",\n\n // Type checking\n \"alwaysStrict\": true,\n \"noFallthroughCasesInSwitch\": true,\n \"noImplicitAny\": true,\n \"noImplicitReturns\": true,\n \"noImplicitThis\": true,\n \"noUnusedLocals\": true,\n \"noUnusedParameters\": true,\n \"strict\": true,\n \"strictFunctionTypes\": true,\n \"strictNullChecks\": true,\n \"strictPropertyInitialization\": true\n }\n }\n `,\n prettierConfig,\n ),\n })\n\n files.push({\n name: 'tsconfig.dist.json',\n contents: await format(\n resolve(packagePath, 'tsconfig.dist.json'),\n outdent`\n {\n \"extends\": \"./tsconfig.settings\",\n \"include\": [\"./src\"],\n \"exclude\": [\"./src/**/*.test.ts\"],\n \"compilerOptions\": {\n \"rootDir\": \".\",\n \"outDir\": \"./dist\",\n \"resolveJsonModule\": true\n }\n }\n `,\n prettierConfig,\n ),\n })\n\n files.push({\n name: 'tsconfig.json',\n contents: await format(\n resolve(packagePath, 'tsconfig.json'),\n outdent`\n {\n \"extends\": \"./tsconfig.settings\",\n \"include\": [\"./**/*.cjs\", \"./**/*.ts\", \"./**/*.tsx\"],\n \"exclude\": [\"./node_modules\"],\n \"compilerOptions\": {\n \"rootDir\": \".\",\n \"outDir\": \"./dist\",\n \"noEmit\": true,\n \"allowJs\": true,\n \"resolveJsonModule\": true,\n }\n }\n `,\n prettierConfig,\n ),\n })\n }\n\n // source file\n if (features.typescript) {\n files.push({\n name: 'package.config.ts',\n contents: await format(\n resolve(packagePath, 'package.config.ts'),\n outdent`\n import {defineConfig} from '@sanity/pkg-utils'\n\n // https://github.com/sanity-io/pkg-utils#configuration\n export default defineConfig({\n // the path to the tsconfig file for distributed builds\n tsconfig: 'tsconfig.dist.json',\n })\n `,\n prettierConfig,\n ),\n })\n\n files.push({\n name: 'src/index.ts',\n contents: await format(\n resolve(packagePath, 'src/index.ts'),\n outdent`\n /** @public */\n export function main(): void {\n //\n }\n `,\n prettierConfig,\n ),\n })\n } else {\n files.push({\n name: 'package.config.js',\n contents: await format(\n resolve(packagePath, 'package.config.js'),\n outdent`\n import {defineConfig} from '@sanity/pkg-utils'\n\n export default defineConfig({\n extract: {\n rules: {\n // do not require internal members to be prefixed with \\`_\\`\n 'ae-internal-missing-underscore': 'off',\n },\n },\n })\n `,\n prettierConfig,\n ),\n })\n\n files.push({\n name: 'src/index.js',\n contents: await format(\n resolve(packagePath, 'src/index.js'),\n outdent`\n /** @public */\n export function main() {\n //\n }\n `,\n prettierConfig,\n ),\n })\n }\n\n // Resolve latest dependencies\n try {\n pkgJson.dependencies = await resolveLatestDeps(pkgJson.dependencies ?? {})\n } catch (error) {\n logger.warn(error instanceof Error ? error.message : error)\n }\n\n // Resolve latest devDependencies\n try {\n pkgJson.devDependencies = await resolveLatestDeps(pkgJson.devDependencies ?? {})\n } catch (error) {\n logger.warn(error instanceof Error ? error.message : error)\n }\n\n files.push({\n name: 'package.json',\n contents: await format(\n resolve(packagePath, 'package.json'),\n JSON.stringify(pkgJson, null, 2),\n prettierConfig,\n ),\n })\n\n return files\n },\n }\n}\n\nfunction format(filepath: string, input: string, prettierOptions: PrettierConfig | undefined) {\n return prettier.format(input, {...prettierOptions, plugins: [], filepath})\n}\n\nasync function resolveLatestDeps(deps: Record<string, string | undefined>) {\n const depsEntries = Object.entries(deps)\n const latestDeps: Record<string, string> = {}\n\n for (const entry of depsEntries) {\n const [name, version] = entry\n\n if (version) {\n const latestVersion = await getLatestVersion(name, version)\n\n latestDeps[name] = latestVersion ? `^${latestVersion}` : version\n }\n }\n\n return latestDeps\n}\n","import {lstat} from 'fs/promises'\nimport {mkdirp} from 'mkdirp'\nimport {resolve} from 'path'\n\nimport {createFromTemplate} from './core/template'\nimport {fileExists} from './fileExists'\nimport {isEmptyDirectory} from './isEmptyDirectory'\nimport {createLogger} from './logger'\nimport {defaultTemplate} from './templates'\n\n/** @public */\nexport async function init(options: {cwd: string; path: string}): Promise<void> {\n if (!options.cwd) {\n throw new Error('Missing required option: cwd')\n }\n\n if (!options.path) {\n throw new Error('Missing required option: path')\n }\n\n const logger = createLogger()\n\n const packagePath = resolve(options.cwd, options.path)\n\n await ensurePackagePath(packagePath)\n\n await createFromTemplate({\n cwd: options.cwd,\n logger,\n template: defaultTemplate,\n packagePath,\n })\n}\n\nasync function ensurePackagePath(packagePath: string): Promise<void> {\n const exists = fileExists(packagePath)\n\n if (!exists) {\n await mkdirp(packagePath)\n\n return\n }\n\n const dir = (await lstat(packagePath)).isDirectory()\n\n if (!dir) {\n throw new Error('the package path is a file, not a directory')\n }\n\n const empty = await isEmptyDirectory(packagePath)\n\n if (!empty) {\n throw new Error('the package directory is not empty')\n }\n}\n"],"names":["logger","relative","prompts","resolve","mkdirp","dirname","writeFile","readdir","parseGitConfig","gitUrlParse","outdent","isRecord","prettier","getLatestVersion","createLogger","fileExists","lstat"],"mappings":";;;;;;;;;;;;;;AAQA,MAAM,eAAe;AAAA,EACnB,QAAQ;AACV;AAGA,eAAsB,mBAAmB,SAKvB;AAChB,QAAM,EAAC,KAAK,QAAAA,SAAQ,aAAa,UAAU,mBAAA,IAAsB,SAE3D,WACJ,OAAO,sBAAuB,aAC1B,MAAM,mBAAmB,EAAC,KAAK,QAAAA,SAAQ,YAAA,CAAY,IACnD;AAEN,EAAAA,QAAO,IAAI,yBAAyBC,KAAS,SAAA,KAAK,WAAW,CAAC;AAE9D,QAAM,kBAA0C,CAAA;AAErC,aAAA,kBAAkB,SAAS,SAAS;AAC7C,UAAM,mBAAmB,eAAe,UAElC,MAAM,MAAMC,iBAAA;AAAA,MAChB;AAAA,QACE,MAAM,aAAa,eAAe,IAAI;AAAA,QACtC,MAAM,eAAe;AAAA,QACrB,SAAS,eAAe;AAAA,QACxB,UAAU,mBAAmB,CAAC,SAAS,iBAAiB,IAAI,IAAI;AAAA,QAChE,SACE,OAAO,eAAe,WAAY,aAC9B,eAAe,QAAQ,eAAe,IACtC,eAAe;AAAA,MACvB;A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Q,KAAK,QAAQ,IAAI;AAErD,QAAM,kBAAkB,WAAW,GAEnC,MAAM,mBAAmB;AAAA,IACvB,KAAK,QAAQ;AAAA,IAAA,QACbH;AAAAA,IACA,UAAU;AAAA,IACV;AAAA,EAAA,CACD;AACH;AAEA,eAAe,kBAAkB,aAAoC;AAG/D,MAAA,CAFWe,OAAAA,WAAW,WAAW,GAExB;AACX,UAAMX,OAAAA,OAAO,WAAW;AAExB;AAAA,EACF;AAIA,MAAI,EAFS,MAAMY,GAAAA,MAAM,WAAW,GAAG,YAAY;AAG3C,UAAA,IAAI,MAAM,6CAA6C;AAK3D,MAAA,CAFU,MAAM,iBAAiB,WAAW;AAGxC,UAAA,IAAI,MAAM,oCAAoC;AAExD;;;;"}
|
|
@@ -32,11 +32,21 @@ function resolveWatchTasks(ctx) {
|
|
|
32
32
|
}
|
|
33
33
|
for (const exp of exports2) {
|
|
34
34
|
const importId = path__default.default.join(pkg.name, exp._path);
|
|
35
|
-
exp.
|
|
35
|
+
exp.source?.endsWith(".ts") && dtsTask.entries.push({
|
|
36
36
|
importId,
|
|
37
37
|
exportPath: exp._path,
|
|
38
38
|
sourcePath: exp.source,
|
|
39
|
-
|
|
39
|
+
targetPaths: index.getTargetPaths(pkg.type, exp)
|
|
40
|
+
}), exp.browser?.source?.endsWith(".ts") && dtsTask.entries.push({
|
|
41
|
+
importId,
|
|
42
|
+
exportPath: exp._path,
|
|
43
|
+
sourcePath: exp.browser.source,
|
|
44
|
+
targetPaths: index.getTargetPaths(pkg.type, exp.browser)
|
|
45
|
+
}), exp.node?.source?.endsWith(".ts") && dtsTask.entries.push({
|
|
46
|
+
importId,
|
|
47
|
+
exportPath: exp._path,
|
|
48
|
+
sourcePath: exp.node.source,
|
|
49
|
+
targetPaths: index.getTargetPaths(pkg.type, exp.node)
|
|
40
50
|
});
|
|
41
51
|
}
|
|
42
52
|
for (const exp of exports2) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.cjs","sources":["../../src/node/resolveWatchTasks.ts","../../src/node/globFiles.ts","../../src/node/watchFiles.ts","../../src/node/watchConfigFiles.ts","../../src/node/watch.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\n\nimport {BuildContext, PkgExport, PkgFormat, PkgRuntime} from './core'\nimport {DtsWatchTask, RollupTaskEntry, RollupWatchTask, WatchTask} from './tasks'\n\n/** @internal */\nexport function resolveWatchTasks(ctx: BuildContext): WatchTask[] {\n const {config, cwd, pkg, target} = ctx\n const tasks: WatchTask[] = []\n\n const exports = Object.entries(ctx.exports || {}).map(\n ([_path, exp]) => ({_path, ...exp}) as PkgExport & {_path: string},\n )\n\n const dtsTask: DtsWatchTask = {\n type: 'watch:dts',\n entries: [],\n }\n\n const rollupTasks: Record<string, RollupWatchTask> = {}\n\n function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {\n const buildId = `${format}:${runtime}`\n\n if (rollupTasks[buildId]) {\n rollupTasks[buildId].entries.push(entry)\n } else {\n rollupTasks[buildId] = {\n type: 'watch:js',\n buildId,\n entries: [entry],\n runtime,\n format,\n target: target[runtime],\n }\n }\n }\n\n // Parse `dts` tasks\n for (const exp of exports) {\n const importId = path.join(pkg.name, exp._path)\n\n if (exp.types) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.source,\n targetPath: exp.types,\n })\n }\n }\n\n // Parse rollup:commonjs:* tasks\n for (const exp of exports) {\n const output = exp.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:commonjs:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:* tasks\n for (const exp of exports) {\n const output = exp.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n if (dtsTask.entries.length) {\n tasks.push(dtsTask)\n }\n\n tasks.push(...Object.values(rollupTasks))\n\n // Write legacy exports files\n if (config?.legacyExports) {\n for (const exp of exports) {\n if (exp._exported && exp._path !== '.') {\n const relativeTargetPath = (exp.browser?.import || exp.import || '').replace(\n /\\.[^/.]+$/,\n '',\n )\n\n if (relativeTargetPath) {\n fs.writeFileSync(\n path.resolve(cwd, `${exp._path}.js`),\n [`// AUTO-GENERATED – DO NOT EDIT`, `export * from '${relativeTargetPath}'`, ``].join(\n '\\n',\n ),\n )\n }\n }\n }\n }\n\n return tasks\n}\n","import globby from 'globby'\nimport path from 'path'\n\nexport function globFiles(patterns: string[]): Promise<string[]> {\n return globby(patterns.map((pattern) => pattern.split(path.sep).join(path.posix.sep)))\n}\n","import chokidar from 'chokidar'\nimport {Observable} from 'rxjs'\n\nexport interface FileEvent {\n type: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir'\n file: string\n}\n\nexport function watchFiles(patterns: string[]): Observable<FileEvent> {\n return new Observable((observer) => {\n const watcher = chokidar.watch(patterns, {\n ignoreInitial: true,\n })\n\n function handleFileEvent(\n type: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir',\n file: string,\n ) {\n observer.next({type, file})\n }\n\n watcher.on('all', handleFileEvent)\n\n return () => {\n watcher.off('all', handleFileEvent)\n watcher.close()\n }\n })\n}\n","import path from 'path'\nimport {Observable} from 'rxjs'\nimport {distinctUntilChanged, scan, startWith} from 'rxjs/operators'\n\nimport {globFiles} from './globFiles'\nimport {Logger} from './logger'\nimport {watchFiles} from './watchFiles'\n\nexport async function watchConfigFiles(options: {\n cwd: string\n logger: Logger\n}): Promise<Observable<string[]>> {\n const {cwd, logger} = options\n\n const initialFiles = await globFiles([\n path.resolve(cwd, 'package.json'),\n path.resolve(cwd, 'package.config.cjs'),\n path.resolve(cwd, 'package.config.js'),\n path.resolve(cwd, 'package.config.ts'),\n ])\n\n const fileEvent$ = watchFiles([\n path.resolve(cwd, 'package.json'),\n path.resolve(cwd, 'package.config.cjs'),\n path.resolve(cwd, 'package.config.js'),\n path.resolve(cwd, 'package.config.ts'),\n ])\n\n return fileEvent$.pipe(\n scan((files, fileEvent) => {\n if (fileEvent.type === 'add') {\n return files.concat(fileEvent.file)\n }\n\n if (fileEvent.type === 'unlink') {\n return files.filter((f) => f !== fileEvent.file)\n }\n\n if (fileEvent.type === 'change') {\n logger.log(\n '--------------------------------------------------------------------------------',\n )\n logger.info(path.relative(cwd, fileEvent.file), 'changed')\n logger.log('')\n\n return files.slice(0) // trigger update\n }\n\n return files\n }, initialFiles),\n startWith(initialFiles),\n distinctUntilChanged(),\n )\n}\n","import path from 'path'\nimport {switchMap} from 'rxjs'\n\nimport {getPkgExtMap, loadConfig, loadPkgWithReporting} from './core'\nimport {createLogger} from './logger'\nimport {resolveBuildContext} from './resolveBuildContext'\nimport {resolveWatchTasks} from './resolveWatchTasks'\nimport {TaskHandler, WatchTask, watchTaskHandlers} from './tasks'\nimport {watchConfigFiles} from './watchConfigFiles'\n\n/** @public */\nexport async function watch(options: {\n cwd: string\n strict?: boolean\n tsconfig?: string\n}): Promise<void> {\n const {cwd, strict = false, tsconfig: tsconfigOption} = options\n\n const logger = createLogger()\n\n const configFiles$ = await watchConfigFiles({cwd, logger})\n\n const ctx$ = configFiles$.pipe(\n switchMap(async (configFiles) => {\n const files = configFiles.map((f) => path.relative(cwd, f))\n\n const packageJsonPath = files.find((f) => f === 'package.json')\n\n if (!packageJsonPath) {\n throw new Error('missing package.json')\n }\n\n const pkg = await loadPkgWithReporting({cwd, logger})\n const config = await loadConfig({cwd})\n const extMap = getPkgExtMap({legacyExports: config?.legacyExports ?? false})\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n\n return resolveBuildContext({config, cwd, extMap, logger, pkg, strict, tsconfig})\n }),\n )\n\n ctx$.subscribe(async (ctx) => {\n const watchTasks = resolveWatchTasks(ctx)\n\n for (const task of watchTasks) {\n const handler = watchTaskHandlers[task.type] as TaskHandler<WatchTask, unknown>\n const result$ = handler.exec(ctx, task)\n\n result$.subscribe({\n error: (err) => {\n ctx.logger.error(err)\n ctx.logger.log()\n\n process.exit(1)\n },\n next: (result) => {\n handler.complete(ctx, task, result)\n },\n complete: () => {\n ctx.logger.success(handler.name(ctx, task))\n ctx.logger.log()\n },\n })\n }\n })\n}\n"],"names":["exports","path","fs","globby","Observable","chokidar","logger","scan","startWith","distinctUntilChanged","createLogger","switchMap","loadPkgWithReporting","loadConfig","getPkgExtMap","resolveBuildContext","watchTaskHandlers"],"mappings":";;;;;;;;;;;;;;AAOO,SAAS,kBAAkB,KAAgC;AAChE,QAAM,EAAC,QAAQ,KAAK,KAAK,OAAA,IAAU,KAC7B,QAAqB,CAAC,GAEtBA,WAAU,OAAO,QAAQ,IAAI,WAAW,CAAE,CAAA,EAAE;AAAA,IAChD,CAAC,CAAC,OAAO,GAAG,OAAO,EAAC,OAAO,GAAG;KAG1B,UAAwB;AAAA,IAC5B,MAAM;AAAA,IACN,SAAS,CAAC;AAAA,EAAA,GAGN,cAA+C,CAAA;AAE5C,WAAA,mBAAmB,QAAmB,SAAqB,OAAwB;AAC1F,UAAM,UAAU,GAAG,MAAM,IAAI,OAAO;AAEhC,gBAAY,OAAO,IACrB,YAAY,OAAO,EAAE,QAAQ,KAAK,KAAK,IAEvC,YAAY,OAAO,IAAI;AAAA,MACrB,MAAM;AAAA,MACN;AAAA,MACA,SAAS,CAAC,KAAK;AAAA,MACf;AAAA,MACA;AAAA,MACA,QAAQ,OAAO,OAAO;AAAA,IAAA;AAAA,EAG5B;AAGA,aAAW,OAAOA,UAAS;AACzB,UAAM,WAAWC,cAAAA,QAAK,KAAK,IAAI,M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A,QAChB,OAAO,CAAC,QAAQ;AACV,cAAA,OAAO,MAAM,GAAG,GACpB,IAAI,OAAO,OAEX,QAAQ,KAAK,CAAC;AAAA,QAChB;AAAA,QACA,MAAM,CAAC,WAAW;AACR,kBAAA,SAAS,KAAK,MAAM,MAAM;AAAA,QACpC;AAAA,QACA,UAAU,MAAM;AACV,cAAA,OAAO,QAAQ,QAAQ,KAAK,KAAK,IAAI,CAAC,GAC1C,IAAI,OAAO,IAAI;AAAA,QACjB;AAAA,MAAA,CACD;AAAA,IACH;AAAA,EAAA,CACD;AACH;;"}
|
|
1
|
+
{"version":3,"file":"watch.cjs","sources":["../../src/node/resolveWatchTasks.ts","../../src/node/globFiles.ts","../../src/node/watchFiles.ts","../../src/node/watchConfigFiles.ts","../../src/node/watch.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\n\nimport type {BuildContext, PkgExport, PkgFormat, PkgRuntime} from './core'\nimport type {DtsWatchTask, RollupTaskEntry, RollupWatchTask, WatchTask} from './tasks'\nimport {getTargetPaths} from './tasks/dts/getTargetPaths'\n\n/** @internal */\nexport function resolveWatchTasks(ctx: BuildContext): WatchTask[] {\n const {config, cwd, pkg, target} = ctx\n const tasks: WatchTask[] = []\n\n const exports = Object.entries(ctx.exports || {}).map(\n ([_path, exp]) => ({_path, ...exp}) as PkgExport & {_path: string},\n )\n\n const dtsTask: DtsWatchTask = {\n type: 'watch:dts',\n entries: [],\n }\n\n const rollupTasks: Record<string, RollupWatchTask> = {}\n\n function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {\n const buildId = `${format}:${runtime}`\n\n if (rollupTasks[buildId]) {\n rollupTasks[buildId].entries.push(entry)\n } else {\n rollupTasks[buildId] = {\n type: 'watch:js',\n buildId,\n entries: [entry],\n runtime,\n format,\n target: target[runtime],\n }\n }\n }\n\n // Parse `dts` tasks\n for (const exp of exports) {\n const importId = path.join(pkg.name, exp._path)\n\n if (exp.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.source,\n targetPaths: getTargetPaths(pkg.type, exp),\n })\n }\n\n if (exp.browser?.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.browser.source,\n targetPaths: getTargetPaths(pkg.type, exp.browser),\n })\n }\n\n if (exp.node?.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.node.source,\n targetPaths: getTargetPaths(pkg.type, exp.node),\n })\n }\n }\n\n // Parse rollup:commonjs:* tasks\n for (const exp of exports) {\n const output = exp.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:commonjs:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:* tasks\n for (const exp of exports) {\n const output = exp.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n if (dtsTask.entries.length) {\n tasks.push(dtsTask)\n }\n\n tasks.push(...Object.values(rollupTasks))\n\n // Write legacy exports files\n if (config?.legacyExports) {\n for (const exp of exports) {\n if (exp._exported && exp._path !== '.') {\n const relativeTargetPath = (exp.browser?.import || exp.import || '').replace(\n /\\.[^/.]+$/,\n '',\n )\n\n if (relativeTargetPath) {\n fs.writeFileSync(\n path.resolve(cwd, `${exp._path}.js`),\n [`// AUTO-GENERATED – DO NOT EDIT`, `export * from '${relativeTargetPath}'`, ``].join(\n '\\n',\n ),\n )\n }\n }\n }\n }\n\n return tasks\n}\n","import globby from 'globby'\nimport path from 'path'\n\nexport function globFiles(patterns: string[]): Promise<string[]> {\n return globby(patterns.map((pattern) => pattern.split(path.sep).join(path.posix.sep)))\n}\n","import chokidar from 'chokidar'\nimport {Observable} from 'rxjs'\n\nexport interface FileEvent {\n type: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir'\n file: string\n}\n\nexport function watchFiles(patterns: string[]): Observable<FileEvent> {\n return new Observable((observer) => {\n const watcher = chokidar.watch(patterns, {\n ignoreInitial: true,\n })\n\n function handleFileEvent(\n type: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir',\n file: string,\n ) {\n observer.next({type, file})\n }\n\n watcher.on('all', handleFileEvent)\n\n return () => {\n watcher.off('all', handleFileEvent)\n watcher.close()\n }\n })\n}\n","import path from 'path'\nimport {Observable} from 'rxjs'\nimport {distinctUntilChanged, scan, startWith} from 'rxjs/operators'\n\nimport {globFiles} from './globFiles'\nimport {Logger} from './logger'\nimport {watchFiles} from './watchFiles'\n\nexport async function watchConfigFiles(options: {\n cwd: string\n logger: Logger\n}): Promise<Observable<string[]>> {\n const {cwd, logger} = options\n\n const initialFiles = await globFiles([\n path.resolve(cwd, 'package.json'),\n path.resolve(cwd, 'package.config.cjs'),\n path.resolve(cwd, 'package.config.js'),\n path.resolve(cwd, 'package.config.ts'),\n ])\n\n const fileEvent$ = watchFiles([\n path.resolve(cwd, 'package.json'),\n path.resolve(cwd, 'package.config.cjs'),\n path.resolve(cwd, 'package.config.js'),\n path.resolve(cwd, 'package.config.ts'),\n ])\n\n return fileEvent$.pipe(\n scan((files, fileEvent) => {\n if (fileEvent.type === 'add') {\n return files.concat(fileEvent.file)\n }\n\n if (fileEvent.type === 'unlink') {\n return files.filter((f) => f !== fileEvent.file)\n }\n\n if (fileEvent.type === 'change') {\n logger.log(\n '--------------------------------------------------------------------------------',\n )\n logger.info(path.relative(cwd, fileEvent.file), 'changed')\n logger.log('')\n\n return files.slice(0) // trigger update\n }\n\n return files\n }, initialFiles),\n startWith(initialFiles),\n distinctUntilChanged(),\n )\n}\n","import path from 'path'\nimport {switchMap} from 'rxjs'\n\nimport {getPkgExtMap, loadConfig, loadPkgWithReporting} from './core'\nimport {createLogger} from './logger'\nimport {resolveBuildContext} from './resolveBuildContext'\nimport {resolveWatchTasks} from './resolveWatchTasks'\nimport {TaskHandler, WatchTask, watchTaskHandlers} from './tasks'\nimport {watchConfigFiles} from './watchConfigFiles'\n\n/** @public */\nexport async function watch(options: {\n cwd: string\n strict?: boolean\n tsconfig?: string\n}): Promise<void> {\n const {cwd, strict = false, tsconfig: tsconfigOption} = options\n\n const logger = createLogger()\n\n const configFiles$ = await watchConfigFiles({cwd, logger})\n\n const ctx$ = configFiles$.pipe(\n switchMap(async (configFiles) => {\n const files = configFiles.map((f) => path.relative(cwd, f))\n\n const packageJsonPath = files.find((f) => f === 'package.json')\n\n if (!packageJsonPath) {\n throw new Error('missing package.json')\n }\n\n const pkg = await loadPkgWithReporting({cwd, logger})\n const config = await loadConfig({cwd})\n const extMap = getPkgExtMap({legacyExports: config?.legacyExports ?? false})\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n\n return resolveBuildContext({config, cwd, extMap, logger, pkg, strict, tsconfig})\n }),\n )\n\n ctx$.subscribe(async (ctx) => {\n const watchTasks = resolveWatchTasks(ctx)\n\n for (const task of watchTasks) {\n const handler = watchTaskHandlers[task.type] as TaskHandler<WatchTask, unknown>\n const result$ = handler.exec(ctx, task)\n\n result$.subscribe({\n error: (err) => {\n ctx.logger.error(err)\n ctx.logger.log()\n\n process.exit(1)\n },\n next: (result) => {\n handler.complete(ctx, task, result)\n },\n complete: () => {\n ctx.logger.success(handler.name(ctx, task))\n ctx.logger.log()\n },\n })\n }\n })\n}\n"],"names":["exports","path","getTargetPaths","fs","globby","Observable","chokidar","logger","scan","startWith","distinctUntilChanged","createLogger","switchMap","loadPkgWithReporting","loadConfig","getPkgExtMap","resolveBu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,GAAG,GACpB,IAAI,OAAO,OAEX,QAAQ,KAAK,CAAC;AAAA,QAChB;AAAA,QACA,MAAM,CAAC,WAAW;AACR,kBAAA,SAAS,KAAK,MAAM,MAAM;AAAA,QACpC;AAAA,QACA,UAAU,MAAM;AACV,cAAA,OAAO,QAAQ,QAAQ,KAAK,KAAK,IAAI,CAAC,GAC1C,IAAI,OAAO,IAAI;AAAA,QACjB;AAAA,MAAA,CACD;AAAA,IACH;AAAA,EAAA,CACD;AACH;;"}
|
package/dist/cli.cjs
CHANGED
|
@@ -3,7 +3,7 @@ var cac = require("cac");
|
|
|
3
3
|
function _interopDefaultCompat(e) {
|
|
4
4
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
5
5
|
}
|
|
6
|
-
var cac__default = /* @__PURE__ */ _interopDefaultCompat(cac), version = "5.
|
|
6
|
+
var cac__default = /* @__PURE__ */ _interopDefaultCompat(cac), version = "5.1.1-canary.0";
|
|
7
7
|
const cli = cac__default.default();
|
|
8
8
|
cli.command("", "Check").alias("check").option("--strict", "Strict mode").option("--tsconfig [tsconfig]", "[string] tsconfig.json").action(async (options) => {
|
|
9
9
|
const { checkAction } = await Promise.resolve().then(function() {
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {ExtractorMessage} from '@microsoft/api-extractor'
|
|
1
|
+
import type {ExtractorMessage} from '@microsoft/api-extractor'
|
|
2
2
|
import {IExtractorMessagesConfig} from '@microsoft/api-extractor'
|
|
3
3
|
import type {NormalizedOutputOptions} from 'rollup'
|
|
4
4
|
import {Observable} from 'rxjs'
|
|
@@ -109,7 +109,7 @@ export declare interface DtsResult {
|
|
|
109
109
|
messages: ExtractorMessage[]
|
|
110
110
|
results: {
|
|
111
111
|
sourcePath: string
|
|
112
|
-
|
|
112
|
+
filePaths: string[]
|
|
113
113
|
}[]
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -120,7 +120,7 @@ export declare interface DtsTask {
|
|
|
120
120
|
exportPath: string
|
|
121
121
|
importId: string
|
|
122
122
|
sourcePath: string
|
|
123
|
-
|
|
123
|
+
targetPaths: string[]
|
|
124
124
|
}[]
|
|
125
125
|
}
|
|
126
126
|
|
|
@@ -134,7 +134,7 @@ export declare interface DtsWatchTask {
|
|
|
134
134
|
exportPath: string
|
|
135
135
|
importId: string
|
|
136
136
|
sourcePath: string
|
|
137
|
-
|
|
137
|
+
targetPaths: string[]
|
|
138
138
|
}[]
|
|
139
139
|
}
|
|
140
140
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {ExtractorMessage} from '@microsoft/api-extractor'
|
|
1
|
+
import type {ExtractorMessage} from '@microsoft/api-extractor'
|
|
2
2
|
import {IExtractorMessagesConfig} from '@microsoft/api-extractor'
|
|
3
3
|
import type {NormalizedOutputOptions} from 'rollup'
|
|
4
4
|
import {Observable} from 'rxjs'
|
|
@@ -109,7 +109,7 @@ export declare interface DtsResult {
|
|
|
109
109
|
messages: ExtractorMessage[]
|
|
110
110
|
results: {
|
|
111
111
|
sourcePath: string
|
|
112
|
-
|
|
112
|
+
filePaths: string[]
|
|
113
113
|
}[]
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -120,7 +120,7 @@ export declare interface DtsTask {
|
|
|
120
120
|
exportPath: string
|
|
121
121
|
importId: string
|
|
122
122
|
sourcePath: string
|
|
123
|
-
|
|
123
|
+
targetPaths: string[]
|
|
124
124
|
}[]
|
|
125
125
|
}
|
|
126
126
|
|
|
@@ -134,7 +134,7 @@ export declare interface DtsWatchTask {
|
|
|
134
134
|
exportPath: string
|
|
135
135
|
importId: string
|
|
136
136
|
sourcePath: string
|
|
137
|
-
|
|
137
|
+
targetPaths: string[]
|
|
138
138
|
}[]
|
|
139
139
|
}
|
|
140
140
|
|
package/dist/index.js
CHANGED
|
@@ -142,10 +142,6 @@ async function loadPkg(options2) {
|
|
|
142
142
|
const buf = await fs.readFile(pkgPath), raw = JSON.parse(buf.toString());
|
|
143
143
|
return validatePkg(raw), raw;
|
|
144
144
|
}
|
|
145
|
-
function assertFirst(a, arr) {
|
|
146
|
-
const aIdx = arr.indexOf(a);
|
|
147
|
-
return aIdx === -1 ? !0 : aIdx === 0;
|
|
148
|
-
}
|
|
149
145
|
function assertLast(a, arr) {
|
|
150
146
|
const aIdx = arr.indexOf(a);
|
|
151
147
|
return aIdx === -1 ? !0 : aIdx === arr.length - 1;
|
|
@@ -165,7 +161,9 @@ async function loadPkgWithReporting(options2) {
|
|
|
165
161
|
if (typeof exp == "string" || "svelte" in exp)
|
|
166
162
|
continue;
|
|
167
163
|
const keys = Object.keys(exp);
|
|
168
|
-
|
|
164
|
+
exp.types && (shouldError = !0, logger.error(
|
|
165
|
+
`exports["${expPath}"]: the \`types\` condition shouldn't be used as dts files are generated in such a way that both CJS and ESM is supported`
|
|
166
|
+
)), exp.module && (shouldError = !0, logger.error(
|
|
169
167
|
`exports["${expPath}"]: the \`module\` condition shouldn't be used as it's not well supported in all bundlers.`
|
|
170
168
|
)), exp.node ? (exp.import && exp.node.import && !assertOrder("node", "import", keys) && (shouldError = !0, logger.error(
|
|
171
169
|
`exports["${expPath}"]: the \`node\` property should come before the \`import\` property`
|
|
@@ -222,7 +220,6 @@ function parseExports(options2) {
|
|
|
222
220
|
const { extMap, pkg, strict } = options2, rootExport = {
|
|
223
221
|
_exported: !0,
|
|
224
222
|
_path: ".",
|
|
225
|
-
types: pkg.types,
|
|
226
223
|
source: pkg.source || "",
|
|
227
224
|
browser: pkg.browser && {
|
|
228
225
|
source: pkg.source || "",
|
|
@@ -233,7 +230,9 @@ function parseExports(options2) {
|
|
|
233
230
|
import: pkg.module,
|
|
234
231
|
default: pkg.module || pkg.main || ""
|
|
235
232
|
}, extraExports = [], errors = [];
|
|
236
|
-
if (pkg.
|
|
233
|
+
if (strict && !pkg.types && pkg.source?.endsWith(".ts") && errors.push(
|
|
234
|
+
"package.json: `types` must be declared for the npm listing to show as a TypeScript module."
|
|
235
|
+
), strict && "typings" in pkg && errors.push("package.json: `typings` should be `types`"), pkg.exports) {
|
|
237
236
|
strict && !pkg.exports["./package.json"] && errors.push('package.json: `exports["./package.json"] must be declared.');
|
|
238
237
|
for (const [exportPath, exportEntry] of Object.entries(pkg.exports))
|
|
239
238
|
if (exportPath.endsWith(".json"))
|
|
@@ -245,8 +244,6 @@ function parseExports(options2) {
|
|
|
245
244
|
'package.json: mismatch between "main" and "exports.require". These must be equal.'
|
|
246
245
|
), exportEntry.import && rootExport.import && exportEntry.import !== rootExport.import && errors.push(
|
|
247
246
|
'package.json: mismatch between "module" and "exports.import" These must be equal.'
|
|
248
|
-
), exportEntry.types && rootExport.types && exportEntry.types !== rootExport.types && errors.push(
|
|
249
|
-
'package.json: mismatch between "types" and "exports.types". These must be equal.'
|
|
250
247
|
), exportEntry.source && rootExport.source && exportEntry.source !== rootExport.source && errors.push(
|
|
251
248
|
'package.json: mismatch between "source" and "exports.source". These must be equal.'
|
|
252
249
|
), Object.assign(rootExport, exportEntry);
|
|
@@ -491,6 +488,25 @@ async function resolveBuildContext(options2) {
|
|
|
491
488
|
}
|
|
492
489
|
};
|
|
493
490
|
}
|
|
491
|
+
const fileEnding = /\.[mc]?js$/, dtsEnding = ".d.ts", mtsEnding = ".d.mts", ctsEnding = ".d.cts";
|
|
492
|
+
function getTargetPaths(_type, expOrBundle) {
|
|
493
|
+
const type = _type === "module" ? "module" : "commonjs", set = /* @__PURE__ */ new Set();
|
|
494
|
+
return expOrBundle?.import && set.add(expOrBundle.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)), expOrBundle?.require && set.add(expOrBundle.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)), isPkgExport(expOrBundle) && (expOrBundle.browser?.source || (expOrBundle.browser?.import && set.add(
|
|
495
|
+
expOrBundle.browser.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
|
|
496
|
+
), expOrBundle.browser?.require && set.add(
|
|
497
|
+
expOrBundle.browser.require.replace(
|
|
498
|
+
fileEnding,
|
|
499
|
+
type === "commonjs" ? dtsEnding : ctsEnding
|
|
500
|
+
)
|
|
501
|
+
)), expOrBundle.node?.source || (expOrBundle.node?.import && set.add(
|
|
502
|
+
expOrBundle.node.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
|
|
503
|
+
), expOrBundle.node?.require && set.add(
|
|
504
|
+
expOrBundle.node.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)
|
|
505
|
+
))), Array.from(set);
|
|
506
|
+
}
|
|
507
|
+
function isPkgExport(exp) {
|
|
508
|
+
return exp?.browser || exp?.node || exp?.default;
|
|
509
|
+
}
|
|
494
510
|
function resolveBuildTasks(ctx) {
|
|
495
511
|
const { config: config2, cwd, pkg, target } = ctx, bundles = config2?.bundles || [], tasks = [], exports = Object.entries(ctx.exports || {}).map(
|
|
496
512
|
([_path, exp]) => ({ _path, ...exp })
|
|
@@ -511,11 +527,30 @@ function resolveBuildTasks(ctx) {
|
|
|
511
527
|
}
|
|
512
528
|
for (const exp of exports) {
|
|
513
529
|
const importId = path$1.join(pkg.name, exp._path);
|
|
514
|
-
exp.
|
|
530
|
+
exp.source?.endsWith(".ts") && dtsTask2.entries.push({
|
|
515
531
|
importId,
|
|
516
532
|
exportPath: exp._path,
|
|
517
533
|
sourcePath: exp.source,
|
|
518
|
-
|
|
534
|
+
targetPaths: getTargetPaths(pkg.type, exp)
|
|
535
|
+
}), exp.browser?.source?.endsWith(".ts") && dtsTask2.entries.push({
|
|
536
|
+
importId,
|
|
537
|
+
exportPath: exp._path,
|
|
538
|
+
sourcePath: exp.browser.source,
|
|
539
|
+
targetPaths: getTargetPaths(pkg.type, exp.browser)
|
|
540
|
+
}), exp.node?.source?.endsWith(".ts") && dtsTask2.entries.push({
|
|
541
|
+
importId,
|
|
542
|
+
exportPath: exp._path,
|
|
543
|
+
sourcePath: exp.node.source,
|
|
544
|
+
targetPaths: getTargetPaths(pkg.type, exp.node)
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
for (const bundle of bundles) {
|
|
548
|
+
const exportPath = (bundle.import || bundle.require).replace(/\.[mc]?js$/, ""), importId = path$1.join(pkg.name, exportPath);
|
|
549
|
+
dtsTask2.entries.push({
|
|
550
|
+
importId,
|
|
551
|
+
exportPath,
|
|
552
|
+
sourcePath: bundle.source,
|
|
553
|
+
targetPaths: getTargetPaths(pkg.type, bundle)
|
|
519
554
|
});
|
|
520
555
|
}
|
|
521
556
|
if (dtsTask2.entries.length && tasks.push(dtsTask2), !ctx.emitDeclarationOnly) {
|
|
@@ -20180,7 +20215,7 @@ async function extractTypes(options2) {
|
|
|
20180
20215
|
distPath,
|
|
20181
20216
|
exportPath,
|
|
20182
20217
|
files,
|
|
20183
|
-
|
|
20218
|
+
filePaths,
|
|
20184
20219
|
projectPath,
|
|
20185
20220
|
rules,
|
|
20186
20221
|
sourceTypesPath,
|
|
@@ -20189,7 +20224,7 @@ async function extractTypes(options2) {
|
|
|
20189
20224
|
tsconfigPath
|
|
20190
20225
|
} = options2, tsdocConfigFile = await createTSDocConfig({
|
|
20191
20226
|
customTags: customTags || []
|
|
20192
|
-
}), extractorConfig = ExtractorConfig.prepare({
|
|
20227
|
+
}), filePath = filePaths[0].replace(/\.d\.[mc]ts$/, ".d.ts"), shouldCleanUpDts = !filePaths.includes(filePath), extractorConfig = ExtractorConfig.prepare({
|
|
20193
20228
|
configObject: createApiExtractorConfig({
|
|
20194
20229
|
bundledPackages,
|
|
20195
20230
|
distPath,
|
|
@@ -20220,17 +20255,18 @@ async function extractTypes(options2) {
|
|
|
20220
20255
|
tsOutDir: tmpPath
|
|
20221
20256
|
}), code = [typesBuf.toString(), ...moduleBlocks].join(`
|
|
20222
20257
|
|
|
20223
|
-
`)
|
|
20224
|
-
|
|
20225
|
-
typesPath
|
|
20226
|
-
|
|
20227
|
-
|
|
20228
|
-
|
|
20229
|
-
|
|
20230
|
-
|
|
20231
|
-
|
|
20232
|
-
|
|
20233
|
-
}
|
|
20258
|
+
`), prettyCode = await prettier.format(code, {
|
|
20259
|
+
...prettierConfig,
|
|
20260
|
+
filepath: typesPath
|
|
20261
|
+
});
|
|
20262
|
+
for (const expFilePath of filePaths) {
|
|
20263
|
+
const expTypesPath = path$1.resolve(distPath, expFilePath);
|
|
20264
|
+
await fs.writeFile(expTypesPath, prettyCode), files.push({
|
|
20265
|
+
type: "types",
|
|
20266
|
+
path: expTypesPath
|
|
20267
|
+
});
|
|
20268
|
+
}
|
|
20269
|
+
return shouldCleanUpDts && (console.warn("Cleaning up .d.ts file", typesPath), await fs.unlink(typesPath)), { extractorResult, messages };
|
|
20234
20270
|
}
|
|
20235
20271
|
async function doExtract(ctx, task) {
|
|
20236
20272
|
const { config: config2, cwd, files, logger, strict, ts: ts2 } = ctx;
|
|
@@ -20246,14 +20282,14 @@ async function doExtract(ctx, task) {
|
|
|
20246
20282
|
const exportPath = entry.exportPath === "." ? "./index" : entry.exportPath, sourceTypesPath = path$1.resolve(
|
|
20247
20283
|
tmpPath,
|
|
20248
20284
|
path$1.relative(rootDir, path$1.resolve(cwd, entry.sourcePath)).replace(/\.ts$/, ".d.ts")
|
|
20249
|
-
),
|
|
20285
|
+
), targetPaths = entry.targetPaths.map((targetPath) => path$1.resolve(cwd, targetPath)), filePaths = targetPaths.map((targetPath) => path$1.relative(outDir, targetPath)), result = await extractTypes({
|
|
20250
20286
|
bundledPackages: config2?.extract?.bundledPackages || [],
|
|
20251
20287
|
customTags: config2?.extract?.customTags,
|
|
20252
20288
|
cwd,
|
|
20253
20289
|
distPath: outDir,
|
|
20254
20290
|
exportPath,
|
|
20255
20291
|
files,
|
|
20256
|
-
|
|
20292
|
+
filePaths,
|
|
20257
20293
|
projectPath: cwd,
|
|
20258
20294
|
rules: config2?.extract?.rules,
|
|
20259
20295
|
sourceTypesPath,
|
|
@@ -20265,7 +20301,7 @@ async function doExtract(ctx, task) {
|
|
|
20265
20301
|
const errors = result.messages.filter((msg) => msg.logLevel === "error");
|
|
20266
20302
|
if (errors.length > 0)
|
|
20267
20303
|
throw await rimraf(tmpPath), new DtsError(`encountered ${errors.length} errors when extracting types`, errors);
|
|
20268
|
-
results.push({ sourcePath: path$1.resolve(cwd, entry.sourcePath),
|
|
20304
|
+
results.push({ sourcePath: path$1.resolve(cwd, entry.sourcePath), filePaths: targetPaths });
|
|
20269
20305
|
}
|
|
20270
20306
|
return await rimraf(tmpPath), { type: "dts", messages, results };
|
|
20271
20307
|
}
|
|
@@ -20273,12 +20309,11 @@ const dtsTask = {
|
|
|
20273
20309
|
name: (_ctx, task) => [
|
|
20274
20310
|
"Build type definitions...",
|
|
20275
20311
|
" entries:",
|
|
20276
|
-
...task.entries.map(
|
|
20277
|
-
(entry)
|
|
20278
|
-
|
|
20279
|
-
|
|
20280
|
-
|
|
20281
|
-
)
|
|
20312
|
+
...task.entries.map((entry) => entry.targetPaths.map((targetPath) => [
|
|
20313
|
+
` - ${chalk.cyan(entry.importId)}: `,
|
|
20314
|
+
`${chalk.yellow(entry.sourcePath)} ${chalk.gray("\u2192")} ${chalk.yellow(targetPath)}`
|
|
20315
|
+
].join("")).join(`
|
|
20316
|
+
`))
|
|
20282
20317
|
].join(`
|
|
20283
20318
|
`),
|
|
20284
20319
|
exec: (ctx, task) => new Observable((observer) => {
|
|
@@ -20298,9 +20333,10 @@ const dtsTask = {
|
|
|
20298
20333
|
}, dtsWatchTask = {
|
|
20299
20334
|
name: (_ctx, task) => [
|
|
20300
20335
|
"build type definitions",
|
|
20301
|
-
...task.entries.map(
|
|
20302
|
-
|
|
20303
|
-
|
|
20336
|
+
...task.entries.map((entry) => entry.targetPaths.map((targetPath) => [
|
|
20337
|
+
` - ${chalk.cyan(entry.importId)}: `,
|
|
20338
|
+
`${chalk.yellow(entry.sourcePath)} ${chalk.gray("\u2192")} ${chalk.yellow(targetPath)}`
|
|
20339
|
+
].join("")))
|
|
20304
20340
|
].join(`
|
|
20305
20341
|
`),
|
|
20306
20342
|
exec: (ctx, task) => new Observable((observer) => {
|
|
@@ -20615,7 +20651,6 @@ function printPackageTree(ctx) {
|
|
|
20615
20651
|
tree.exports = Object.fromEntries(
|
|
20616
20652
|
Object.entries(exports).filter(([, entry]) => entry._exported).map(([exportPath, entry]) => {
|
|
20617
20653
|
const exp = {
|
|
20618
|
-
types: void 0,
|
|
20619
20654
|
source: fileInfo(entry.source),
|
|
20620
20655
|
browser: void 0,
|
|
20621
20656
|
require: void 0,
|
|
@@ -20623,7 +20658,7 @@ function printPackageTree(ctx) {
|
|
|
20623
20658
|
import: void 0,
|
|
20624
20659
|
default: fileInfo(entry.default)
|
|
20625
20660
|
};
|
|
20626
|
-
return entry.
|
|
20661
|
+
return entry.browser ? (exp.browser = { source: fileInfo(entry.browser.source) }, entry.browser.import && (exp.browser.import = fileInfo(entry.browser.import)), entry.browser.require && (exp.browser.require = fileInfo(entry.browser.require))) : delete exp.browser, entry.require ? exp.require = fileInfo(entry.require) : delete exp.require, entry.node ? (exp.node = {}, entry.node.source && (exp.node.source = fileInfo(entry.node.source)), entry.node.import && (exp.node.import = fileInfo(entry.node.import)), entry.node.require && (exp.node.require = fileInfo(entry.node.require))) : delete exp.node, entry.import ? exp.import = fileInfo(entry.import) : delete exp.import, [chalk.cyan(path$1.join(pkg.name, exportPath)), exp];
|
|
20627
20662
|
})
|
|
20628
20663
|
), logger.log(treeify.asTree(tree, !0, !0));
|
|
20629
20664
|
}
|
|
@@ -20632,8 +20667,8 @@ async function check(options2) {
|
|
|
20632
20667
|
if (printPackageTree(ctx), strict) {
|
|
20633
20668
|
const missingFiles = [];
|
|
20634
20669
|
for (const [, exp] of Object.entries(ctx.exports || {}))
|
|
20635
|
-
exp.source && !fileExists(path$1.resolve(cwd, exp.source)) && missingFiles.push(exp.source), exp.require && !fileExists(path$1.resolve(cwd, exp.require)) && missingFiles.push(exp.require), exp.import && !fileExists(path$1.resolve(cwd, exp.import)) && missingFiles.push(exp.import)
|
|
20636
|
-
missingFiles.length && (logger.error(
|
|
20670
|
+
exp.source && !fileExists(path$1.resolve(cwd, exp.source)) && missingFiles.push(exp.source), exp.require && !fileExists(path$1.resolve(cwd, exp.require)) && missingFiles.push(exp.require), exp.import && !fileExists(path$1.resolve(cwd, exp.import)) && missingFiles.push(exp.import);
|
|
20671
|
+
ctx.pkg.types && !fileExists(path$1.resolve(cwd, ctx.pkg.types)) && missingFiles.push(ctx.pkg.types), missingFiles.length && (logger.error(`missing files: ${missingFiles.join(", ")}`), process.exit(1));
|
|
20637
20672
|
const exportPaths = {
|
|
20638
20673
|
require: [],
|
|
20639
20674
|
import: []
|
|
@@ -20899,9 +20934,7 @@ const RE_NAME = /^(?:@(?:[a-z0-9-*~][a-z0-9-*._~]*)\/)?[a-z0-9-~][a-z0-9-._~]*$/
|
|
|
20899
20934
|
}, pkgJson.bugs = {
|
|
20900
20935
|
url: `https://${repo.source}/${repo.owner}/${repo.name}/issues`
|
|
20901
20936
|
}, pkgJson.homepage = `https://${repo.source}/${repo.owner}/${repo.name}#readme`), features.typescript) {
|
|
20902
|
-
pkgJson.types = "./dist/index.d.ts"
|
|
20903
|
-
const mainExport = pkgJson.exports?.["."];
|
|
20904
|
-
isRecord(mainExport) && (mainExport.types = "./dist/index.d.ts"), pkgJson.scripts = {
|
|
20937
|
+
pkgJson.types = "./dist/index.d.ts", pkgJson.scripts = {
|
|
20905
20938
|
...pkgJson.scripts,
|
|
20906
20939
|
"ts:check": "tsc --build"
|
|
20907
20940
|
};
|
|
@@ -21213,11 +21246,21 @@ function resolveWatchTasks(ctx) {
|
|
|
21213
21246
|
}
|
|
21214
21247
|
for (const exp of exports) {
|
|
21215
21248
|
const importId = path$1.join(pkg.name, exp._path);
|
|
21216
|
-
exp.
|
|
21249
|
+
exp.source?.endsWith(".ts") && dtsTask2.entries.push({
|
|
21217
21250
|
importId,
|
|
21218
21251
|
exportPath: exp._path,
|
|
21219
21252
|
sourcePath: exp.source,
|
|
21220
|
-
|
|
21253
|
+
targetPaths: getTargetPaths(pkg.type, exp)
|
|
21254
|
+
}), exp.browser?.source?.endsWith(".ts") && dtsTask2.entries.push({
|
|
21255
|
+
importId,
|
|
21256
|
+
exportPath: exp._path,
|
|
21257
|
+
sourcePath: exp.browser.source,
|
|
21258
|
+
targetPaths: getTargetPaths(pkg.type, exp.browser)
|
|
21259
|
+
}), exp.node?.source?.endsWith(".ts") && dtsTask2.entries.push({
|
|
21260
|
+
importId,
|
|
21261
|
+
exportPath: exp._path,
|
|
21262
|
+
sourcePath: exp.node.source,
|
|
21263
|
+
targetPaths: getTargetPaths(pkg.type, exp.node)
|
|
21221
21264
|
});
|
|
21222
21265
|
}
|
|
21223
21266
|
for (const exp of exports) {
|