### Build and Develop Zile Package with npm Source: https://github.com/wevm/zile/blob/main/examples/basic/README.md This snippet shows the commands to build and prepare the Zile package for development. `npm run build` transpiles the code, and `npm run dev` creates necessary symlinks for a development environment. These commands are crucial for packaging the project for distribution. ```shell npm run build # Builds and transpiles the package npm run dev # Create symlinks for development ``` -------------------------------- ### Install Zile and TypeScript Source: https://github.com/wevm/zile/blob/main/README.md Installs Zile and TypeScript as development dependencies for your project. Ensure both `zile` and `typescript` are installed to use Zile's build functionalities. ```bash npm i zile typescript -D ``` -------------------------------- ### Create New Zile Project Source: https://github.com/wevm/zile/blob/main/README.md Initializes a new TypeScript library project with opinionated Zile defaults. Run this command in your terminal to start a new project. ```bash npx zile new ``` -------------------------------- ### Run Zile Build Source: https://github.com/wevm/zile/blob/main/README.md Executes the Zile build process for your TypeScript library. This command should be run after configuring your `package.json` and installing dependencies. ```bash npm run build ``` -------------------------------- ### Configure Binary/CLI Entrypoint in package.json Source: https://github.com/wevm/zile/blob/main/README.md Sets up a binary entry point for your CLI tool using the `bin` field in `package.json`. Zile automatically maps the source file to its built counterpart. ```diff { "name": "my-pkg", "version": "0.0.0", "type": "module", + "bin": "./src/cli.ts" } ``` -------------------------------- ### Configure Multiple Binary Entrypoints in package.json Source: https://github.com/wevm/zile/blob/main/README.md Configures multiple named binary entry points for your CLI tools by using an object for the `bin` field in `package.json`. Ensure a `.src` suffix is used for source files. ```diff { "name": "my-pkg", "version": "0.0.0", "type": "module", + "bin": { + "foo.src": "./src/cli.ts" + "bar.src": "./src/cli2.ts" + } } ``` -------------------------------- ### Zile CLI Usage and Commands Source: https://github.com/wevm/zile/blob/main/README.md This snippet outlines the general usage of the Zile CLI, its available commands for project management, and how to access help for specific commands. ```sh zile/0.0.0 Usage: $ zile [root] Commands: [root] build Build package dev Resolve package exports to source for development new Create a new zile project publish:prepare Prepare package for publishing publish:post Post-process package after publishing For more info, run any command with the `--help` flag: $ zile --help $ zile build --help $ zile dev --help $ zile new --help $ zile publish:prepare --help $ zile publish:post --help ``` -------------------------------- ### Configure Single CLI Entrypoint with Zile Source: https://github.com/wevm/zile/blob/main/README.md Specifies a single CLI entrypoint for your package using the 'bin' field. Zile creates both the built binary and preserves a '.src' reference to the original source file. ```json { "name": "my-cli", "version": "0.0.0", "type": "module", "bin": "./src/cli.ts" } ``` ```json { "name": "my-cli", "version": "0.0.0", "type": "module", "bin": { "my-cli": "./dist/cli.js", "my-cli.src": "./src/cli.ts" } } ``` -------------------------------- ### Configure Multiple Entrypoints in package.json Source: https://github.com/wevm/zile/blob/main/README.md Defines multiple entry points for your library using the `exports` field in `package.json`. Zile handles remapping these to their respective built files. ```diff { "name": "my-pkg", "version": "0.0.0", "type": "module", + "exports": { + ".": "./src/index.ts", + "./utils": "./src/utils.ts" + } } ``` -------------------------------- ### Configure Multiple CLI Entrypoints with Zile Source: https://github.com/wevm/zile/blob/main/README.md Specifies multiple CLI entrypoints for your package using the object format for the 'bin' field. Keys with a '.src' suffix indicate source files, and Zile creates corresponding built versions without the suffix. ```json { "name": "my-cli", "version": "0.0.0", "type": "module", "bin": { "foo.src": "./src/cli-foo.ts", "bar.src": "./src/cli-bar.ts" } } ``` ```json { "name": "my-cli", "version": "0.0.0", "type": "module", "bin": { "foo": "./dist/cli-foo.js", "foo.src": "./src/cli-foo.ts", "bar": "./dist/cli-bar.js", "bar.src": "./src/cli-bar.ts" } } ``` -------------------------------- ### Package.checkInput - Validate package configuration Source: https://context7.com/wevm/zile/llms.txt Validates that all entry points specified in package.json (main, exports, bin) point to existing files. Throws descriptive errors for missing files. ```APIDOC ## Package.checkInput - Validate package configuration ### Description Validates that all entry points specified in `package.json` (`main`, `exports`, `bin`) point to existing files. Throws descriptive errors for missing files. ### Method (Implied asynchronous function call) ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **cwd** (string) - The current working directory. - **outDir** (string) - The output directory for the build. ### Request Example ```typescript import * as Package from 'zile' try { await Package.Package.checkInput({ cwd: process.cwd(), outDir: './dist', }) console.log('Package configuration is valid') } catch (error) { console.error(error.message) // Example: "`./src/missing.ts` does not exist on `package.json#main`" } ``` ### Response #### Success Response (void) Indicates that the package configuration is valid. No specific return value. #### Response Example ``` Package configuration is valid ``` ``` -------------------------------- ### Configure Multiple Package Entrypoints with Zile Source: https://github.com/wevm/zile/blob/main/README.md Enables specifying multiple entrypoints for your package. Zile expands each entrypoint to include types and built files, managing their paths in the 'exports' field. ```json { "name": "my-pkg", "version": "0.0.0", "type": "module", "exports": { ".": "./src/index.ts", "./utils": "./src/utils.ts" } } ``` ```json { "name": "my-pkg", "version": "0.0.0", "type": "module", "main": "./dist/index.js", "module": "./dist/index.js", "types": "./dist/index.d.ts", "exports": { ".": { "src": "./src/index.ts", "types": "./dist/index.d.ts", "default": "./dist/index.js" }, "./utils": { "src": "./src/utils.ts", "types": "./dist/utils.d.ts", "default": "./dist/utils.js" } } } ``` -------------------------------- ### Configure Single Entrypoint in package.json Source: https://github.com/wevm/zile/blob/main/README.md Specifies a single entry point for your library using the `main` field in `package.json`. Zile will automatically remap this to the built file during the build process. ```diff { "name": "my-pkg", "version": "0.0.0", "type": "module", + "main": "./src/index.ts" } ``` -------------------------------- ### Control Published Package Fields with [!start-pkg] in Zile Source: https://github.com/wevm/zile/blob/main/README.md Allows control over which fields from package.json are included when publishing. Fields after the '[!start-pkg]' comment are picked for the published package, excluding development-only fields. ```json { "scripts": { "build": "zile build", "publish": "zile publish:prepare && npm publish && zile publish:post", "test": "vitest" }, "devDependencies": { "typescript": "^5.0.0" }, "[!start-pkg]": "", "name": "my-pkg", "version": "0.0.0", "type": "module", "main": "./src/index.ts", "dependencies": { "some-lib": "^1.0.0" } } ``` -------------------------------- ### Package.getEntries - Extract entry points from package.json Source: https://context7.com/wevm/zile/llms.txt Analyzes package.json to extract all source files and asset files that need to be processed. Distinguishes between TypeScript/JavaScript files to transpile and other assets to copy. ```APIDOC ## Package.getEntries - Extract entry points from package.json ### Description Analyzes `package.json` to extract all source files and asset files that need to be processed. Distinguishes between TypeScript/JavaScript files to transpile and other assets to copy. ### Method (Implied asynchronous function call) ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **cwd** (string) - The current working directory. - **pkgJson** (object) - The package.json object. ### Request Example ```typescript import * as Package from 'zile' const pkgJson = { main: './src/index.ts', exports: { '.': './src/index.ts', './utils': './src/utils.ts', './types': './src/types.d.ts', }, bin: { 'cli.src': './src/cli.ts', }, } const { assets, sources } = await Package.Package.getEntries({ cwd: process.cwd(), pkgJson, }) console.log(sources) // ['/absolute/path/src/index.ts', '/absolute/path/src/utils.ts', '/absolute/path/src/cli.ts'] console.log(assets) // ['/absolute/path/src/types.d.ts'] ``` ### Response #### Success Response (object) - **assets** (array) - An array of absolute paths to asset files. - **sources** (array) - An array of absolute paths to source files (TypeScript/JavaScript). #### Response Example ```json { "sources": [ "/absolute/path/src/index.ts", "/absolute/path/src/utils.ts", "/absolute/path/src/cli.ts" ], "assets": [ "/absolute/path/src/types.d.ts" ] } ``` ``` -------------------------------- ### Validate Package Configuration Source: https://context7.com/wevm/zile/llms.txt Validates that all entry points specified in package.json (`main`, `exports`, `bin`) correctly point to existing files. Throws descriptive errors if any files are missing. ```typescript import * as Package from 'zile' try { await Package.Package.checkInput({ cwd: process.cwd(), outDir: './dist', }) console.log('Package configuration is valid') } catch (error) { console.error(error.message) // Example: "`./src/missing.ts` does not exist on `package.json#main`" } ``` -------------------------------- ### Configure Package Main Entrypoint with Zile Source: https://github.com/wevm/zile/blob/main/README.md Specifies a single entrypoint for your package. Zile transforms the source file path to point to the built file and automatically generates 'exports', 'module', and 'types' fields for the published package. ```json { "name": "my-pkg", "version": "0.0.0", "type": "module", "main": "./src/index.ts" } ``` ```json { "name": "my-pkg", "version": "0.0.0", "type": "module", "main": "./dist/index.js", "module": "./dist/index.js", "types": "./dist/index.d.ts", "exports": { ".": { "src": "./src/index.ts", "types": "./dist/index.d.ts", "default": "./dist/index.js" } } } ``` -------------------------------- ### Package.decoratePackageJson - Transform package.json for publishing Source: https://context7.com/wevm/zile/llms.txt Rewrites package.json fields to point to built artifacts instead of source files. Expands simple exports into full export maps with src, types, and default conditions. ```APIDOC ## Package.decoratePackageJson - Transform package.json for publishing ### Description Rewrites `package.json` fields to point to built artifacts instead of source files. Expands simple exports into full export maps with `src`, `types`, and `default` conditions. ### Method (Implied asynchronous function call) ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **pkgJson** (object) - The original package.json object. - **options** (object) - **cwd** (string) - The current working directory. - **outDir** (string) - The output directory for built artifacts. - **sourceDir** (string) - The source directory of the project. - **assets** (array) - An array of asset files to include. - **link** (boolean) - Whether symlinks were used for development. ### Request Example ```typescript import * as Package from 'zile' const pkgJson = { name: 'my-lib', main: './src/index.ts', bin: './src/cli.ts', } const transformed = await Package.Package.decoratePackageJson(pkgJson, { cwd: process.cwd(), outDir: './dist', sourceDir: './src', assets: [], link: false, }) console.log(transformed) ``` ### Response #### Success Response (object) - **transformed package.json** (object) - The modified package.json object with updated paths for built artifacts. #### Response Example ```json { "name": "my-lib", "type": "module", "sideEffects": false, "main": "./dist/index.js", "module": "./dist/index.js", "types": "./dist/index.d.ts", "bin": { "my-lib": "./dist/cli.js", "my-lib.src": "./src/cli.ts" }, "exports": { ".": { "src": "./src/index.ts", "types": "./dist/index.d.ts", "default": "./dist/index.js" } } } ``` ``` -------------------------------- ### Package.build - Build a TypeScript package Source: https://context7.com/wevm/zile/llms.txt Transpiles TypeScript source files to JavaScript with type definitions, or creates symlinks for development mode. Transforms package.json fields to reference built artifacts in the output directory. ```APIDOC ## Package.build - Build a TypeScript package ### Description Transpiles TypeScript source files to JavaScript with type definitions, or creates symlinks for development mode. Transforms `package.json` fields to reference built artifacts in the output directory. ### Method (Implied asynchronous function call) ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **cwd** (string) - The current working directory. - **project** (string, optional) - Path to the tsconfig.json file. - **tsgo** (boolean, optional) - Whether to use tsgo for faster transpilation (defaults to false, using tsc). - **link** (boolean, optional) - Whether to create symlinks for development mode (defaults to false). ### Request Example ```typescript import * as Package from 'zile' // Production build - transpile source to dist/ const result = await Package.Package.build({ cwd: process.cwd(), project: './tsconfig.json', tsgo: false, }) console.log(result.packageJson) // Transformed package.json with dist/ paths console.log(result.tsConfig) // Resolved tsconfig.json used for build // Development mode - create symlinks instead of transpiling const devResult = await Package.Package.build({ cwd: process.cwd(), link: true, }) ``` ### Response #### Success Response (Object) - **packageJson** (object) - The transformed package.json content. - **tsConfig** (object) - The resolved tsconfig.json object used for the build. #### Response Example ```json { "packageJson": { /* transformed package.json */ }, "tsConfig": { /* tsconfig.json object */ } } ``` ``` -------------------------------- ### Zile CLI Options Source: https://github.com/wevm/zile/blob/main/README.md This snippet details the available options for the Zile CLI, which control aspects like the working directory, included files, TypeScript configuration, and transpilation. ```sh Options: --cwd Working directory to build --includes Glob patterns to include --project Path to tsconfig.json file, relative to the working directory. --tsgo Use tsgo for transpilation -v, --version Display version number -h, --help Display this message ``` -------------------------------- ### Add Build Script to package.json Source: https://github.com/wevm/zile/blob/main/README.md Adds a `build` script to your `package.json` file that executes the Zile build command. This allows you to build your TypeScript library by running `npm run build`. ```diff { "name": "my-pkg", "version": "0.0.0", "type": "module", "main": "./src/index.ts" + "scripts": { + "build": "zile" + }, ... } ``` -------------------------------- ### Cli.run - Programmatic CLI Command Execution Source: https://context7.com/wevm/zile/llms.txt Executes Zile CLI commands programmatically by parsing arguments and invoking the corresponding functionality. This allows for integration of Zile's build, development, and project creation tools into custom scripts or other applications. ```typescript import * as Cli from 'zile' // Run build command await Cli.Cli.run({ args: ['build', '--cwd', './my-package', '--tsgo'], }) // Run dev mode with linking await Cli.Cli.run({ args: ['dev', '--cwd', './my-package'], }) // Create new project await Cli.Cli.run({ args: ['new'], }) // Prepare for publishing await Cli.Cli.run({ args: ['publish:prepare', '--cwd', './my-package'], }) ``` -------------------------------- ### Build TypeScript Package (Production/Development) Source: https://context7.com/wevm/zile/llms.txt Transpiles TypeScript source files to JavaScript with type definitions for production, or creates symlinks for development builds. It also transforms package.json fields to reference the built artifacts. ```typescript import * as Package from 'zile' // Production build - transpile source to dist/ const result = await Package.Package.build({ cwd: process.cwd(), project: './tsconfig.json', tsgo: false, }) console.log(result.packageJson) // Transformed package.json with dist/ paths console.log(result.tsConfig) // Resolved tsconfig.json used for build // Development mode - create symlinks instead of transpiling const devResult = await Package.Package.build({ cwd: process.cwd(), link: true, }) ``` -------------------------------- ### Extract Entry Points from package.json Source: https://context7.com/wevm/zile/llms.txt Analyzes package.json to extract all source files and asset files that require processing. It differentiates between TypeScript/JavaScript files needing transpilation and other assets to be copied. ```typescript import * as Package from 'zile' const pkgJson = { main: './src/index.ts', exports: { '.': './src/index.ts', './utils': './src/utils.ts', './types': './src/types.d.ts', }, bin: { 'cli.src': './src/cli.ts', }, } const { assets, sources } = await Package.Package.getEntries({ cwd: process.cwd(), pkgJson, }) console.log(sources) // ['/absolute/path/src/index.ts', '/absolute/path/src/utils.ts', '/absolute/path/src/cli.ts'] console.log(assets) // ['/absolute/path/src/types.d.ts'] ``` -------------------------------- ### Packages.build - Build Packages in Workspace Source: https://context7.com/wevm/zile/llms.txt Finds and builds all packages within a workspace in parallel. This function combines the capabilities of package discovery (`Packages.find`) and building, making it ideal for monorepo build workflows. It returns an array of results for each successfully built package. ```typescript import * as Packages from 'zile' // Build all packages in a monorepo const results = await Packages.Packages.build({ cwd: process.cwd(), includes: ['packages/*', '!packages/internal/**'], }) console.log(`Built ${results.length} packages`) for (const result of results) { console.log(result.packageJson.name, 'built successfully') } ``` -------------------------------- ### Package.transpile - Transpile TypeScript to JavaScript Source: https://context7.com/wevm/zile/llms.txt Executes TypeScript compiler (tsc or tsgo) to transpile source files. Creates temporary tsconfig with required compiler options and cleans up after build. ```APIDOC ## Package.transpile - Transpile TypeScript to JavaScript ### Description Executes TypeScript compiler (`tsc` or `tsgo`) to transpile source files. Creates temporary tsconfig with required compiler options and cleans up after build. ### Method (Implied asynchronous function call) ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **cwd** (string) - The current working directory. - **sources** (array of strings) - An array of paths to the source files to transpile. - **project** (string, optional) - Path to the tsconfig.json file. - **tsgo** (boolean, optional) - Whether to use tsgo for faster transpilation (defaults to false, using tsc). ### Request Example ```typescript import * as Package from 'zile' try { const result = await Package.Package.transpile({ cwd: process.cwd(), sources: ['./src/index.ts', './src/utils.ts'], project: './tsconfig.json', tsgo: false, // Use tsc }) console.log('Build successful') console.log(result.tsConfig.compilerOptions.outDir) // './dist' } catch (error) { console.error('Build failed:', error.message) } // Using tsgo for faster transpilation await Package.Package.transpile({ cwd: process.cwd(), sources: ['./src/index.ts'], tsgo: true, }) ``` ### Response #### Success Response (object) - **tsConfig** (object) - The resolved tsconfig.json object used for the build. #### Response Example ```json { "tsConfig": { "compilerOptions": { "outDir": "./dist", // ... other compiler options } } } ``` ``` -------------------------------- ### Transform package.json for Publishing Source: https://context7.com/wevm/zile/llms.txt Rewrites package.json fields to point to built artifacts instead of source files. It expands simple exports into full export maps with `src`, `types`, and `default` conditions, preparing the package for distribution. ```typescript import * as Package from 'zile' const pkgJson = { name: 'my-lib', main: './src/index.ts', bin: './src/cli.ts', } const transformed = await Package.Package.decoratePackageJson(pkgJson, { cwd: process.cwd(), outDir: './dist', sourceDir: './src', assets: [], link: false, }) console.log(transformed) // { // name: 'my-lib', // type: 'module', // sideEffects: false, // main: './dist/index.js', // module: './dist/index.js', // types: './dist/index.d.ts', // bin: { // 'my-lib': './dist/cli.js', // 'my-lib.src': './src/cli.ts' // }, // exports: { // '.': { // src: './src/index.ts', // types: './dist/index.d.ts', // default: './dist/index.js' // } // } // } ``` -------------------------------- ### Packages.find - Find Packages in Directory Source: https://context7.com/wevm/zile/llms.txt Searches for packages, defined as directories containing a `package.json` file, that match specified glob patterns. This function is particularly useful for managing monorepo structures and identifying individual packages within a workspace. ```typescript import * as Packages from 'zile' // Find all packages, excluding node_modules const packages = await Packages.Packages.find({ cwd: process.cwd(), includes: ['**', '!**/node_modules/**'], }) console.log(packages) // ['/absolute/path/packages/foo', '/absolute/path/packages/bar'] // Find packages matching specific pattern const specificPackages = await Packages.Packages.find({ cwd: './packages', includes: ['foo/**', 'bar/**'], }) ``` -------------------------------- ### Package.readTsconfigJson - Read and Parse tsconfig.json Source: https://context7.com/wevm/zile/llms.txt Reads and resolves the `tsconfig.json` file, including any extended configurations. It leverages `tsconfck` to ensure proper resolution of `extends` and other TypeScript configuration features. This function is essential for understanding the project's compilation settings. ```typescript import * as Package from 'zile' const tsConfig = await Package.Package.readTsconfigJson({ cwd: process.cwd(), project: './tsconfig.json', }) console.log(tsConfig.compilerOptions?.module) // 'nodenext' console.log(tsConfig.compilerOptions?.outDir) // './dist' console.log(tsConfig.include) // ['src/**/*'] ``` -------------------------------- ### Transpile TypeScript to JavaScript Source: https://context7.com/wevm/zile/llms.txt Executes the TypeScript compiler (`tsc` or `tsgo`) to transpile source files. It creates a temporary tsconfig with necessary compiler options and performs cleanup after the build process. ```typescript import * as Package from 'zile' try { const result = await Package.Package.transpile({ cwd: process.cwd(), sources: ['./src/index.ts', './src/utils.ts'], project: './tsconfig.json', tsgo: false, // Use tsc }) console.log('Build successful') console.log(result.tsConfig.compilerOptions.outDir) // './dist' } catch (error) { console.error('Build failed:', error.message) } // Using tsgo for faster transpilation await Package.Package.transpile({ cwd: process.cwd(), sources: ['./src/index.ts'], tsgo: true, }) ``` -------------------------------- ### Package.readPackageJson - Read and Parse package.json Source: https://context7.com/wevm/zile/llms.txt Reads the `package.json` file from the current working directory with caching enabled. It returns the parsed JSON object representing the package manifest. This is useful for accessing project metadata programmatically. ```typescript import * as Package from 'zile' const pkgJson = await Package.Package.readPackageJson({ cwd: process.cwd(), }) console.log(pkgJson.name) // 'my-package' console.log(pkgJson.version) // '1.0.0' console.log(pkgJson.exports) // { '.': './src/index.ts' } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.