From 5c1c873c0cf23e51bd8d21a4444c3db93bbeb6fe Mon Sep 17 00:00:00 2001 From: wangyiming Date: Thu, 15 Aug 2024 11:42:58 +0800 Subject: [PATCH] chore: rename the function --- README.md | 11 ++++++----- src/index.ts | 11 ++++++++++- tests/__snapshots__/nde.test.ts.snap | 10 ++++++++++ tests/fixtures/project1/src/package.json | 1 - tests/nde.test.ts | 4 ++-- 5 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 tests/__snapshots__/nde.test.ts.snap delete mode 100644 tests/fixtures/project1/src/package.json diff --git a/README.md b/README.md index fe3a672..9bc441b 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,20 @@ -# Nde (Node.js Dependencies Extractor) +# Nde (Node.js Dependencies Emitter) + +`nde` is a utility that analyzes your Node.js project's source code to extract the necessary dependencies and files required for deployment and emits these files to a designed node_modules directory that can be used for the deployment. `nde` can simplify the deployment flow and greatly reduce the size of the deployment package. -`nde` is a utility that analyzes your Node.js project's source code to extract only the necessary dependencies and files required for deployment. By emitting these essential files to a new directory, nde simplifies the deployment process and significantly reduces the deployment package size. ## Features -- **Efficient File Extraction and Size Reduction**: Automatically detects and extracts only the files required by your project,generate well-designed, production-ready node_modules directory, significantly reducing deployment package size. It can be used with some popular Node.js frameworks such as Express, Koa and NestJS e.g.. +- **Efficient File Extraction and Size Reduction**: Automatically detects and extracts only the files required by your project,generate to designed, production-ready node_modules directory, significantly reducing deployment package size. It can be used with some popular Node.js frameworks such as Express, Koa and NestJS e.g.. - **Monorepo Tool Agnostic**: Compatible with any monorepo tool (e.g., pnpm, Rush, Nx, Turborepo) and offers faster deployment compared to deployment capability of monorepo tools. - **Rich Configuration and Extensibility**: Supports customizable file inclusion rules, cache configuration, and other extensible options to meet diverse project needs. ## Usage ``` -import { handleDependencies } from 'nde' +import { nodeDepEmit } from 'nde' -handleDependencies({ +nodeDepEmit({ appDir: appDirectory, serverRootDir: outputDirectory, }) diff --git a/src/index.ts b/src/index.ts index 685c701..8def55a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,7 +27,7 @@ export type { NodeFileTraceOptions } from '@vercel/nft'; export { nodeFileTrace } from '@vercel/nft'; -export const handleDependencies = async ({ +export const nodeDepEmit = async ({ appDir, sourceDir, includeEntries, @@ -43,8 +43,17 @@ export const handleDependencies = async ({ }, traceOptions, }: { + /** + * Directory of the project + */ appDir: string; + /** + * The directory where the code will be analyzed, all js files in that directory will be used as entries, and the node_modules directory will be generated in that directory + */ sourceDir: string; + /** + * Some files to include, generally some files not analyzed by the code + */ includeEntries?: string[]; traceFiles?: typeof defaultTraceFiles; entryFilter?: (filePath: string) => boolean; diff --git a/tests/__snapshots__/nde.test.ts.snap b/tests/__snapshots__/nde.test.ts.snap new file mode 100644 index 0000000..8532c59 --- /dev/null +++ b/tests/__snapshots__/nde.test.ts.snap @@ -0,0 +1,10 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`handle dependencies > basic usage 1`] = ` +{ + "dependencies": {}, + "name": "project1-prod-prod-prod", + "private": true, + "version": "1.0.0", +} +`; diff --git a/tests/fixtures/project1/src/package.json b/tests/fixtures/project1/src/package.json deleted file mode 100644 index cad7e3e..0000000 --- a/tests/fixtures/project1/src/package.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"project1-prod-prod","version":"1.0.0","private":true,"dependencies":{}} diff --git a/tests/nde.test.ts b/tests/nde.test.ts index 4ce29db..32c01c3 100644 --- a/tests/nde.test.ts +++ b/tests/nde.test.ts @@ -2,7 +2,7 @@ import { expect, describe, it, afterEach } from 'vitest' import path from 'node:path' import fse from 'fs-extra' -import { handleDependencies } from '../src'; +import { nodeDepEmit } from '../src'; describe('handle dependencies', () => { const project1Dir = path.join(__dirname, 'fixtures/project1'); @@ -15,7 +15,7 @@ describe('handle dependencies', () => { await fse.remove(outputPkgPath); }) it('basic usage', async() => { - await handleDependencies({ + await nodeDepEmit({ appDir: project1Dir, sourceDir: srcDir, })