-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
chore: release v2.0.0
Showing
22 changed files
with
3,407 additions
and
2,654 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,3 +1 @@ | ||
import stubb from '../dist/index.mjs' | ||
|
||
stubb() | ||
import '../dist/cli.mjs' |
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,9 +1,12 @@ | ||
{ | ||
"name": "package-b", | ||
"exports": { | ||
".": { | ||
"default": "./dist/index.cjs" | ||
} | ||
}, | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"stubb": "esno ../../bin/stubb.js" | ||
"stubb": "esno ../../bin/stubb.js --esm=false --ts=false --fill" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('F:/stubb/examples/package-c/src/index.ts') |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from 'F:/stubb/examples/package-c/src/index.ts' | ||
export { default } from 'F:/stubb/examples/package-c/src/index.ts' |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from 'F:/stubb/examples/package-c/src/index.ts' | ||
export { default } from 'F:/stubb/examples/package-c/src/index.ts' |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from 'F:/stubb/examples/package-c/src/index.ts' | ||
export { default } from 'F:/stubb/examples/package-c/src/index.ts' |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from 'F:/stubb/examples/package-c/src/index.ts' | ||
export { default } from 'F:/stubb/examples/package-c/src/index.ts' |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from 'F:/stubb/examples/package-c/src/index.ts' | ||
export { default } from 'F:/stubb/examples/package-c/src/index.ts' |
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,6 +1,16 @@ | ||
{ | ||
"name": "package-c", | ||
"exports": { | ||
".": { | ||
"types": "./ouput/index.d.ts", | ||
"import": "./ouput/index.mjs", | ||
"require": "./ouput/index.cjs" | ||
} | ||
}, | ||
"main": "ouput/index.cjs", | ||
"module": "ouput/index.mjs", | ||
"types": "ouput/index.d.ts", | ||
"scripts": { | ||
"stubb": "esno ../../bin/stubb.js" | ||
"stubb": "esno ../../bin/stubb.js --outputDir=ouput --fill" | ||
} | ||
} |
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,9 +1,9 @@ | ||
{ | ||
"name": "stubb", | ||
"type": "module", | ||
"version": "1.3.0", | ||
"version": "2.0.0", | ||
"packageManager": "[email protected]", | ||
"description": "Stub 'dist' link your project based on package.json during the development", | ||
"description": "Stub dist link your project during the development", | ||
"author": "yu <[email protected]> (https://github.com/zhengyuzi)", | ||
"license": "MIT", | ||
"homepage": "https://github.com/zhengyuzi/stubb", | ||
|
@@ -48,14 +48,18 @@ | |
"prepare": "simple-git-hooks" | ||
}, | ||
"dependencies": { | ||
"citty": "^0.1.6", | ||
"consola": "^3.2.3", | ||
"fast-glob": "^3.3.2", | ||
"fs-extra": "^11.2.0", | ||
"mlly": "^1.7.1" | ||
"mlly": "^1.7.1", | ||
"path-parse": "^1.0.7" | ||
}, | ||
"devDependencies": { | ||
"@antfu/eslint-config": "^2.21.3", | ||
"@types/fs-extra": "^11.0.4", | ||
"@types/node": "^20.10.3", | ||
"@types/path-parse": "^1.0.22", | ||
"eslint": "^9.6.0", | ||
"esno": "^4.0.0", | ||
"lint-staged": "^15.2.0", | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { defineCommand, runMain } from 'citty' | ||
import { description, name, version } from '../package.json' | ||
import { | ||
DEFAULT_ENTRY, | ||
DEFAULT_OUTPUT_DIR, | ||
OUTPUT_SUFFIXES, | ||
} from './constants' | ||
import { stub } from './stub' | ||
import { fill } from './fill' | ||
|
||
const main = defineCommand({ | ||
meta: { | ||
name, | ||
version, | ||
description, | ||
}, | ||
args: { | ||
entries: { | ||
type: 'positional', | ||
description: `Entry file paths. Default: ${DEFAULT_ENTRY}`, | ||
required: false, | ||
}, | ||
outputDir: { | ||
type: 'string', | ||
description: `The folder name/path of the output file. Default: ${DEFAULT_OUTPUT_DIR}`, | ||
}, | ||
fill: { | ||
type: 'boolean', | ||
description: 'Auto fill in exports/main/module/types in package.json. Default: false', | ||
}, | ||
esm: { | ||
type: 'boolean', | ||
description: 'Open esm. Default: true', | ||
}, | ||
cjs: { | ||
type: 'boolean', | ||
description: 'Open cjs. Default: true', | ||
}, | ||
ts: { | ||
type: 'boolean', | ||
description: 'Open Types. Default: true', | ||
}, | ||
}, | ||
async run({ args }) { | ||
const { esm = true, cjs = true, ts = true, fill: isFill = false } = args | ||
|
||
const entries = (args.entries || DEFAULT_ENTRY).split(',') | ||
|
||
const outputDir = args.outputDir || DEFAULT_OUTPUT_DIR | ||
|
||
const outputSuffixes = { | ||
...(cjs && { cjs: OUTPUT_SUFFIXES.cjs }), | ||
...(esm && { esm: OUTPUT_SUFFIXES.esm }), | ||
...(ts && { ts: OUTPUT_SUFFIXES.ts }), | ||
} | ||
|
||
await stub(entries, outputDir, outputSuffixes) | ||
|
||
if (isFill) | ||
await fill(entries, outputDir, outputSuffixes) | ||
}, | ||
}) | ||
|
||
runMain(main) |
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,9 +1,26 @@ | ||
export const StubbDefaultConfig = { | ||
entry: 'src/index', | ||
export const DEFAULT_ENTRY = 'src/index' | ||
|
||
export const DEFAULT_OUTPUT_DIR = 'dist' | ||
|
||
export const SUFFIX_JS = '.js' | ||
export const SUFFIX_CJS = '.cjs' | ||
export const SUFFIX_MJS = '.mjs' | ||
export const SUFFIX_TS = '.d.ts' | ||
|
||
export const OUTPUT_SUFFIXES = { | ||
cjs: [SUFFIX_JS, SUFFIX_CJS], | ||
esm: [SUFFIX_JS, SUFFIX_MJS], | ||
ts: [SUFFIX_TS], | ||
} | ||
|
||
export const EXPORT_CONTENT = { | ||
defaultExport: `export { default } from 'path'`, | ||
namedExport: `export * from 'path'`, | ||
moduleExport: `module.exports = require('path')`, | ||
} | ||
|
||
export const ExitCode = { | ||
Success: 0, | ||
InvalidArgument: 9, | ||
FatalException: 1, | ||
export const EXIT_CODE = { | ||
success: 0, | ||
invalidArgument: 9, | ||
fatalException: 1, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { resolve } from 'node:path' | ||
import pathParse from 'path-parse' | ||
import fs from 'fs-extra' | ||
import consola from 'consola' | ||
import { OUTPUT_SUFFIXES, SUFFIX_CJS, SUFFIX_MJS, SUFFIX_TS } from './constants' | ||
|
||
export interface PackageExportFields { | ||
[key: string]: { | ||
types?: string | ||
default?: string | ||
import?: string | ||
require?: string | ||
} | ||
} | ||
|
||
export interface Fields { | ||
exports: PackageExportFields | ||
main?: string | ||
module?: string | ||
types?: string | ||
} | ||
|
||
/** | ||
* Auto fill in exports/main/module/types in package.json. | ||
*/ | ||
export async function fill( | ||
entries: string[], | ||
outputDir: string, | ||
outputSuffixes: Partial<typeof OUTPUT_SUFFIXES> = OUTPUT_SUFFIXES, | ||
) { | ||
const jsonPath = './package.json' | ||
|
||
const fields: Fields = { | ||
exports: {}, | ||
} | ||
|
||
const dir = outputDir.replace(/\/$/, '') | ||
|
||
const dirPath = !dir.startsWith('.') && !dir.startsWith('/') ? `./${dir}` : dir | ||
|
||
for (const entry of entries) { | ||
const { name } = pathParse(entry) | ||
|
||
const exportName = name === 'index' ? '.' : `./${name}` | ||
|
||
if (outputSuffixes.cjs && outputSuffixes.esm) { | ||
fields.exports[exportName] = { | ||
...fields.exports[exportName], | ||
import: `${dirPath}/${name}${SUFFIX_MJS}`, | ||
require: `${dirPath}/${name}${SUFFIX_CJS}`, | ||
} | ||
|
||
if (!fields.main) | ||
fields.main = `${dir}/${name}${SUFFIX_CJS}` | ||
|
||
if (!fields.module) | ||
fields.module = `${dir}/${name}${SUFFIX_MJS}` | ||
} | ||
else if (outputSuffixes.cjs) { | ||
fields.exports[exportName] = { | ||
...fields.exports[exportName], | ||
default: `${dirPath}/${name}${SUFFIX_CJS}`, | ||
} | ||
|
||
if (!fields.main) | ||
fields.main = `${dir}/${name}${SUFFIX_CJS}` | ||
} | ||
else if (outputSuffixes.esm) { | ||
fields.exports[exportName] = { | ||
...fields.exports[exportName], | ||
default: `${dirPath}/${name}${SUFFIX_MJS}`, | ||
} | ||
|
||
if (!fields.main) | ||
fields.main = `${dir}/${name}${SUFFIX_MJS}` | ||
|
||
if (!fields.module) | ||
fields.module = `${dir}/${name}${SUFFIX_MJS}` | ||
} | ||
|
||
if (outputSuffixes.ts) { | ||
fields.exports[exportName] = { | ||
...fields.exports[exportName], | ||
types: `${dirPath}/${name}${SUFFIX_TS}`, | ||
} | ||
|
||
if (!fields.types) | ||
fields.types = `${dir}/${name}${SUFFIX_TS}` | ||
} | ||
} | ||
|
||
try { | ||
const json = await fs.readJson(jsonPath) | ||
await fs.outputJson(jsonPath, { ...json, ...fields }, { spaces: 2 }) | ||
consola.success(`Autofill success! ${resolve(jsonPath)}`) | ||
} | ||
catch (err) { | ||
consola.error(`Autofill Fail! ${resolve(jsonPath)} ${err}`) | ||
} | ||
} |
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 +1,3 @@ | ||
export { stub as default } from './stub' | ||
export * from './constants' | ||
export * from './stub' | ||
export * from './fill' |
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 was deleted.
Oops, something went wrong.
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