@savvy-web/rslib-builder 0.1.1 → 0.1.2
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/index.d.ts +21 -14
- package/index.js +9 -13
- package/package.json +2 -3
- package/.npmignore +0 -2
- package/api.model.json +0 -3022
package/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* - **Package.json Transformation**: Automatic path updates, PNPM catalog resolution
|
|
13
13
|
* - **TypeScript Declaration Bundling**: Using tsgo and API Extractor
|
|
14
14
|
* - **File Array Generation**: Automatic files array creation for package.json
|
|
15
|
-
* - **API Model Generation**: Optional api.
|
|
15
|
+
* - **API Model Generation**: Optional `<packageName>.api.json` for documentation tooling
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* Basic usage in rslib.config.ts:
|
|
@@ -48,7 +48,7 @@ import type { SourceConfig } from '@rsbuild/core';
|
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Options for API model generation.
|
|
51
|
-
* When enabled, generates an api.
|
|
51
|
+
* When enabled, generates an `<unscopedPackageName>.api.json` file using API Extractor.
|
|
52
52
|
*
|
|
53
53
|
* @remarks
|
|
54
54
|
* API models are only generated for the main "index" entry point (the "." export).
|
|
@@ -66,15 +66,9 @@ export declare interface ApiModelOptions {
|
|
|
66
66
|
enabled?: boolean;
|
|
67
67
|
/**
|
|
68
68
|
* Filename for the generated API model file.
|
|
69
|
-
* @defaultValue
|
|
69
|
+
* @defaultValue `<unscopedPackageName>.api.json` (e.g., `rslib-builder.api.json`)
|
|
70
70
|
*/
|
|
71
71
|
filename?: string;
|
|
72
|
-
/**
|
|
73
|
-
* Whether to add a .npmignore file that excludes the API model file.
|
|
74
|
-
* This is useful when the API model is for internal tooling only.
|
|
75
|
-
* @defaultValue true
|
|
76
|
-
*/
|
|
77
|
-
npmIgnore?: boolean;
|
|
78
72
|
/**
|
|
79
73
|
* Local paths to copy the API model and package.json to.
|
|
80
74
|
* Used for local testing with documentation systems.
|
|
@@ -82,7 +76,10 @@ export declare interface ApiModelOptions {
|
|
|
82
76
|
* @remarks
|
|
83
77
|
* Each path must be a directory. The parent directory must exist,
|
|
84
78
|
* but the final directory will be created if it doesn't exist.
|
|
85
|
-
* Both
|
|
79
|
+
* Both the API model and the processed package.json will be copied.
|
|
80
|
+
*
|
|
81
|
+
* The API model file is emitted to dist but excluded from npm publish
|
|
82
|
+
* (added as negated pattern `!<filename>` in the `files` array).
|
|
86
83
|
*
|
|
87
84
|
* @example
|
|
88
85
|
* ```typescript
|
|
@@ -229,8 +226,10 @@ export declare interface DtsPluginOptions {
|
|
|
229
226
|
buildTarget?: "dev" | "npm";
|
|
230
227
|
/**
|
|
231
228
|
* Options for API model generation.
|
|
232
|
-
* When enabled, generates an api.
|
|
229
|
+
* When enabled, generates an `<unscopedPackageName>.api.json` file in the dist directory.
|
|
233
230
|
* Only applies when bundle is true.
|
|
231
|
+
*
|
|
232
|
+
* The API model is excluded from npm publish (not added to `files` array).
|
|
234
233
|
*/
|
|
235
234
|
apiModel?: ApiModelOptions | boolean;
|
|
236
235
|
}
|
|
@@ -414,6 +413,14 @@ export declare function generateTsgoArgs(options: {
|
|
|
414
413
|
*/
|
|
415
414
|
export declare function getTsgoBinPath(): string;
|
|
416
415
|
|
|
416
|
+
/**
|
|
417
|
+
* Extracts the unscoped package name from a potentially scoped package name.
|
|
418
|
+
* @param name - The package name (e.g., `@scope/package` or `package`)
|
|
419
|
+
* @returns The unscoped name (e.g., `package`)
|
|
420
|
+
* @internal
|
|
421
|
+
*/
|
|
422
|
+
export declare function getUnscopedPackageName(name: string): string;
|
|
423
|
+
|
|
417
424
|
/**
|
|
418
425
|
* @public
|
|
419
426
|
* Node library builder class
|
|
@@ -564,13 +571,13 @@ export declare interface NodeLibraryBuilderOptions {
|
|
|
564
571
|
transform?: TransformPackageJsonFn;
|
|
565
572
|
/**
|
|
566
573
|
* Options for API model generation.
|
|
567
|
-
* When enabled, generates an api.
|
|
574
|
+
* When enabled, generates an `<unscopedPackageName>.api.json` file in the dist directory.
|
|
568
575
|
* Only applies when target is "npm".
|
|
569
576
|
*
|
|
570
577
|
* @remarks
|
|
571
|
-
* The generated
|
|
578
|
+
* The generated API model file contains the full API documentation
|
|
572
579
|
* in a machine-readable format for use by documentation generators.
|
|
573
|
-
*
|
|
580
|
+
* The file is emitted to dist but excluded from npm publish (added as negated pattern in `files` array).
|
|
574
581
|
*
|
|
575
582
|
* @example
|
|
576
583
|
* ```typescript
|
package/index.js
CHANGED
|
@@ -394,6 +394,9 @@ const TSConfigs = {
|
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
396
|
};
|
|
397
|
+
function getUnscopedPackageName(name) {
|
|
398
|
+
return name.startsWith("@") ? name.split("/")[1] ?? name : name;
|
|
399
|
+
}
|
|
397
400
|
function getTsgoBinPath() {
|
|
398
401
|
const cwd = process.cwd();
|
|
399
402
|
const localTsgoBin = (0, external_node_path_.join)(cwd, "node_modules", ".bin", "tsgo");
|
|
@@ -446,7 +449,7 @@ async function bundleDtsFiles(options) {
|
|
|
446
449
|
const bundledFiles = new Map();
|
|
447
450
|
let apiModelPath;
|
|
448
451
|
const apiModelEnabled = true === apiModel || "object" == typeof apiModel && (void 0 === apiModel.enabled || true === apiModel.enabled);
|
|
449
|
-
const apiModelFilename = "object" == typeof apiModel && apiModel.filename ? apiModel.filename : "api.
|
|
452
|
+
const apiModelFilename = "object" == typeof apiModel && apiModel.filename ? apiModel.filename : "api.json";
|
|
450
453
|
getApiExtractorPath();
|
|
451
454
|
const { Extractor, ExtractorConfig } = await import("@microsoft/api-extractor");
|
|
452
455
|
for (const [entryName, sourcePath] of entryPoints){
|
|
@@ -742,20 +745,13 @@ function runTsgo(options) {
|
|
|
742
745
|
}
|
|
743
746
|
core_logger.info(`${picocolors.dim(`[${envId}]`)} Emitted ${emittedCount} bundled declaration file${1 === emittedCount ? "" : "s"} through asset pipeline`);
|
|
744
747
|
if (apiModelPath) {
|
|
745
|
-
const
|
|
748
|
+
const defaultApiModelFilename = packageJson.name ? `${getUnscopedPackageName(packageJson.name)}.api.json` : "api.json";
|
|
749
|
+
const apiModelFilename = "object" == typeof options.apiModel && options.apiModel.filename ? options.apiModel.filename : defaultApiModelFilename;
|
|
746
750
|
const apiModelContent = await promises_readFile(apiModelPath, "utf-8");
|
|
747
751
|
const apiModelSource = new context.sources.OriginalSource(apiModelContent, apiModelFilename);
|
|
748
752
|
context.compilation.emitAsset(apiModelFilename, apiModelSource);
|
|
749
|
-
if (filesArray) filesArray.add(apiModelFilename);
|
|
750
|
-
core_logger.info(`${picocolors.dim(`[${envId}]`)} Emitted API model: ${apiModelFilename}`);
|
|
751
|
-
const shouldAddNpmIgnore = true === options.apiModel || "object" == typeof options.apiModel && false !== options.apiModel.npmIgnore;
|
|
752
|
-
if (shouldAddNpmIgnore) {
|
|
753
|
-
const npmIgnoreContent = `# Exclude API model from npm publish (used by internal tooling)\n${apiModelFilename}\n`;
|
|
754
|
-
const npmIgnoreSource = new context.sources.OriginalSource(npmIgnoreContent, ".npmignore");
|
|
755
|
-
context.compilation.emitAsset(".npmignore", npmIgnoreSource);
|
|
756
|
-
if (filesArray) filesArray.add(".npmignore");
|
|
757
|
-
core_logger.info(`${picocolors.dim(`[${envId}]`)} Emitted .npmignore to exclude ${apiModelFilename}`);
|
|
758
|
-
}
|
|
753
|
+
if (filesArray) filesArray.add(`!${apiModelFilename}`);
|
|
754
|
+
core_logger.info(`${picocolors.dim(`[${envId}]`)} Emitted API model: ${apiModelFilename} (excluded from npm publish)`);
|
|
759
755
|
const isCI = "true" === process.env.GITHUB_ACTIONS || "true" === process.env.CI;
|
|
760
756
|
const localPaths = "object" == typeof options.apiModel ? options.apiModel.localPaths : void 0;
|
|
761
757
|
if (localPaths && localPaths.length > 0 && !isCI) for (const localPath of localPaths){
|
|
@@ -1518,4 +1514,4 @@ const PackageJsonTransformPlugin = (options = {})=>{
|
|
|
1518
1514
|
});
|
|
1519
1515
|
}
|
|
1520
1516
|
}
|
|
1521
|
-
export { AutoEntryPlugin, DtsPlugin, EntryExtractor, FilesArrayPlugin, NodeLibraryBuilder, PackageJsonTransformPlugin, PackageJsonTransformer, PnpmCatalog, collectDtsFiles, ensureTempDeclarationDir, findTsConfig, generateTsgoArgs, getTsgoBinPath, stripSourceMapComment };
|
|
1517
|
+
export { AutoEntryPlugin, DtsPlugin, EntryExtractor, FilesArrayPlugin, NodeLibraryBuilder, PackageJsonTransformPlugin, PackageJsonTransformer, PnpmCatalog, collectDtsFiles, ensureTempDeclarationDir, findTsConfig, generateTsgoArgs, getTsgoBinPath, getUnscopedPackageName, stripSourceMapComment };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@savvy-web/rslib-builder",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "RSlib-based build system for Node.js libraries with automatic package.json transformation, TypeScript declaration bundling, and multi-target support",
|
|
6
6
|
"homepage": "https://github.com/savvy-web/rslib-builder",
|
|
@@ -72,10 +72,9 @@
|
|
|
72
72
|
]
|
|
73
73
|
},
|
|
74
74
|
"files": [
|
|
75
|
-
".
|
|
75
|
+
"!rslib-builder.api.json",
|
|
76
76
|
"LICENSE",
|
|
77
77
|
"README.md",
|
|
78
|
-
"api.model.json",
|
|
79
78
|
"index.d.ts",
|
|
80
79
|
"index.js",
|
|
81
80
|
"package.json",
|
package/.npmignore
DELETED