├── .gitignore ├── .prettierrc ├── LICENSE ├── README.md ├── lerna.json ├── package-lock.json ├── package.json ├── packages ├── babel-plugin-esm-import-rewrite │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── dist-node │ │ │ └── index.js │ │ ├── dist-src │ │ │ ├── index.js │ │ │ └── validate-specifier.js │ │ ├── dist-types │ │ │ ├── index.d.ts │ │ │ └── validate-specifier.d.ts │ │ └── package.json │ ├── src │ │ ├── index.ts │ │ └── validate-specifier.ts │ └── tsconfig.json ├── plugin-build-deno │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── README.md │ │ ├── dist-node │ │ │ └── index.js │ │ ├── dist-src │ │ │ └── index.js │ │ ├── dist-types │ │ │ └── index.d.ts │ │ └── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── plugin-build-node │ ├── README.md │ ├── custom-types │ │ └── babel-plugin-dynamic-import-node-babel-7.d.ts │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── README.md │ │ ├── dist-node │ │ │ ├── index.js │ │ │ └── index.js.map │ │ ├── dist-src │ │ │ └── index.js │ │ ├── dist-types │ │ │ └── index.d.ts │ │ └── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── plugin-build-types │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── README.md │ │ ├── dist-node │ │ │ └── index.js │ │ ├── dist-src │ │ │ └── index.js │ │ ├── dist-types │ │ │ └── index.d.ts │ │ └── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── plugin-build-umd │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── README.md │ │ ├── dist-node │ │ │ └── index.js │ │ ├── dist-src │ │ │ └── index.js │ │ ├── dist-types │ │ │ └── index.d.ts │ │ └── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── plugin-build-web │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── README.md │ │ ├── dist-node │ │ │ └── index.js │ │ ├── dist-src │ │ │ └── index.js │ │ ├── dist-types │ │ │ └── index.d.ts │ │ └── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── plugin-bundle-node │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── README.md │ │ ├── dist-node │ │ │ └── index.js │ │ ├── dist-src │ │ │ └── index.js │ │ ├── dist-types │ │ │ └── index.d.ts │ │ └── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── plugin-bundle-types │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── README.md │ │ ├── dist-node │ │ │ └── index.js │ │ ├── dist-src │ │ │ └── index.js │ │ ├── dist-types │ │ │ └── index.d.ts │ │ └── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── plugin-bundle-web │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── README.md │ │ ├── dist-node │ │ │ └── index.js │ │ ├── dist-src │ │ │ └── index.js │ │ ├── dist-types │ │ │ └── index.d.ts │ │ └── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── plugin-copy-assets │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── README.md │ │ ├── dist-node │ │ │ └── index.js │ │ ├── dist-src │ │ │ └── index.js │ │ ├── dist-types │ │ │ └── index.d.ts │ │ └── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── plugin-simple-bin │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── README.md │ │ ├── dist-node │ │ │ └── index.js │ │ ├── dist-src │ │ │ └── index.js │ │ └── package.json │ ├── src │ │ └── index.js │ └── tsconfig.json ├── plugin-source-bucklescript │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── README.md │ │ ├── dist-node │ │ │ └── index.js │ │ ├── dist-src │ │ │ └── index.js │ │ ├── dist-types │ │ │ └── index.d.ts │ │ └── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── plugin-standard-pkg │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── README.md │ │ ├── dist-node │ │ │ ├── index.js │ │ │ └── index.js.map │ │ ├── dist-src │ │ │ └── index.js │ │ ├── dist-types │ │ │ └── index.d.ts │ │ └── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── plugin-transform-imports │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── plugin-ts-standard-pkg │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── README.md │ │ ├── dist-node │ │ │ ├── index.js │ │ │ └── index.js.map │ │ ├── dist-src │ │ │ └── index.js │ │ ├── dist-types │ │ │ └── index.d.ts │ │ └── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── plugin-wasm-assemblyscript │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── README.md │ │ ├── dist-node │ │ │ └── index.js │ │ ├── dist-src │ │ │ └── index.js │ │ └── package.json │ ├── src │ │ └── index.js │ └── tsconfig.json ├── plugin-wasm-bindings │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── pkg │ │ ├── README.md │ │ ├── dist-node │ │ │ └── index.js │ │ ├── dist-src │ │ │ └── index.js │ │ └── package.json │ └── src │ │ └── index.js └── types │ ├── dist-node │ └── index.js │ ├── dist-src │ └── index.js │ ├── dist-types │ └── index.d.ts │ ├── package-lock.json │ ├── package.json │ └── pkg │ ├── dist-node │ └── index.js │ ├── dist-src │ └── index.js │ ├── dist-types │ └── index.d.ts │ └── package.json └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | /packages/*/node_modules 2 | /packages/*/pkg 3 | !/packages/plugin-standard-pkg/pkg 4 | !/packages/plugin-ts-standard-pkg/pkg 5 | !/packages/plugin-build-node/pkg 6 | /node_modules 7 | lerna-debug.log 8 | todo/ 9 | .DS_Store 10 | *.log 11 | /.nyc_output 12 | /coverage 13 | /dist-* 14 | /dist 15 | /dist-debug 16 | /artifacts 17 | /updates 18 | .vs 19 | *.msi 20 | *.nupkg 21 | /tmp/ 22 | .idea 23 | .pnp 24 | .vscode/ 25 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all", 4 | "bracketSpacing": false, 5 | "printWidth": 120, 6 | "parser": "typescript" 7 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Fred K. Schott 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | "packages/*" 4 | ], 5 | "version": "0.9.2" 6 | } 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "root", 3 | "private": true, 4 | "scripts": { 5 | "version": "lerna version", 6 | "build": "lerna run build", 7 | "format": "prettier --write packages/*/src/**/*.ts", 8 | "publish": "lerna publish from-package --contents pkg", 9 | "nuke": "lerna exec \"rm -f package-lock.json npm-shrinkwrap.json\" && lerna clean --yes && lerna bootstrap && lerna exec --stream -- \"test -f package-lock.json || npm install --package-lock-only\"" 10 | }, 11 | "devDependencies": { 12 | "lerna": "^3.16.4", 13 | "prettier": "^1.18.2" 14 | }, 15 | "dependencies": {} 16 | } 17 | -------------------------------------------------------------------------------- /packages/babel-plugin-esm-import-rewrite/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/babel-plugin-esm-import-rewrite", 3 | "license": "MIT", 4 | "version": "0.9.2", 5 | "main": "pkg/dist-node/index.js", 6 | "publishConfig": { 7 | "access": "public" 8 | }, 9 | "@pika/pack": { 10 | "pipeline": [ 11 | [ 12 | "@pika/plugin-ts-standard-pkg" 13 | ], 14 | [ 15 | "@pika/plugin-build-node" 16 | ] 17 | ] 18 | }, 19 | "scripts": { 20 | "build": "pika-pack build" 21 | }, 22 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593", 23 | "devDependencies": { 24 | "@pika/pack": "^0.5.0", 25 | "@pika/plugin-build-node": "^0.9.2", 26 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 27 | "@types/node": "^10.12.18", 28 | "typescript": "^3.0.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/babel-plugin-esm-import-rewrite/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | import nodeFs from 'fs'; 2 | import url from 'url'; 3 | import nodePath from 'path'; 4 | import { validateDynamicImportArguments } from './validate-specifier.js'; 5 | const BareIdentifierFormat = /^((?:@[^\/]+\/)?[^\/]+)(\/.*)?$/; 6 | export default function transform({}) { 7 | function rewriteImport(specifier, { opts, file }) { 8 | const { deps, addExtensions } = opts; 9 | try { 10 | url.parse(specifier); 11 | } 12 | catch (err) { 13 | return; 14 | } 15 | // URL w/o protocol 16 | if (specifier.substr(0, 2) === '//') { 17 | return; // Leave it alone 18 | } 19 | // Local path 20 | if (['.', '/'].indexOf(specifier.charAt(0)) >= 0) { 21 | if (addExtensions) { 22 | const extname = nodePath.extname(specifier); 23 | if (extname === '.js') { 24 | return; 25 | } 26 | if (extname) { 27 | console.warn('Unexpected file extension:', specifier); 28 | return; 29 | } 30 | const resolvedPath = nodePath.resolve(nodePath.dirname(file.opts.filename), specifier); 31 | try { 32 | const stat = nodeFs.lstatSync(resolvedPath); 33 | if (stat.isDirectory()) { 34 | return specifier + '/index.js'; 35 | } 36 | } 37 | catch (err) { 38 | // do nothing 39 | } 40 | return specifier + '.js'; 41 | } 42 | return; 43 | } 44 | // A 'bare' identifier 45 | const match = BareIdentifierFormat.exec(specifier); 46 | if (deps && match) { 47 | const packageName = match[1]; 48 | // const file = match[2] || ''; 49 | return deps[packageName]; 50 | } 51 | } 52 | return { 53 | visitor: { 54 | 'ImportDeclaration|ExportNamedDeclaration|ExportAllDeclaration'(path, { opts, file }) { 55 | if (!path.node.source) { 56 | return; 57 | } 58 | const rewrittenSpecifier = rewriteImport(path.node.source.value, { opts, file }); 59 | if (rewrittenSpecifier) { 60 | path.node.source.value = rewrittenSpecifier; 61 | } 62 | }, 63 | Import(path, { opts, file }) { 64 | const errors = validateDynamicImportArguments(path); 65 | if (errors.size > 0) { 66 | return; 67 | } 68 | const [importPath] = path.parent.arguments; 69 | const rewrittenSpecifier = rewriteImport(importPath.value, { opts, file }); 70 | if (rewrittenSpecifier) { 71 | importPath.value = rewrittenSpecifier; 72 | } 73 | }, 74 | }, 75 | }; 76 | } 77 | -------------------------------------------------------------------------------- /packages/babel-plugin-esm-import-rewrite/pkg/dist-src/validate-specifier.js: -------------------------------------------------------------------------------- 1 | function getLineCol(node) { 2 | const loc = node.loc.start; 3 | // return chalk.dim(`[${loc.line}:${loc.column}]`); 4 | return `[${loc.line}:${loc.column}]`; 5 | } 6 | export function validateDynamicImportArguments(path) { 7 | if (path.parent.arguments.length !== 1) { 8 | return new Set([ 9 | `${getLineCol(path.node)} "\`import()\` only accepts 1 argument, but got ${path.parent.arguments.length}`, 10 | ]); 11 | } 12 | const [argNode] = path.parent.arguments; 13 | if (argNode.type !== 'StringLiteral') { 14 | return new Set([ 15 | `${getLineCol(path.node)} Pika expects strings as \`import()\` arguments. Treating this as an absolute file path.`, 16 | ]); 17 | } 18 | return new Set(); 19 | } 20 | -------------------------------------------------------------------------------- /packages/babel-plugin-esm-import-rewrite/pkg/dist-types/index.d.ts: -------------------------------------------------------------------------------- 1 | export default function transform({}: {}): any; 2 | -------------------------------------------------------------------------------- /packages/babel-plugin-esm-import-rewrite/pkg/dist-types/validate-specifier.d.ts: -------------------------------------------------------------------------------- 1 | export declare function validateDynamicImportArguments(path: any): Set; 2 | -------------------------------------------------------------------------------- /packages/babel-plugin-esm-import-rewrite/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/babel-plugin-esm-import-rewrite", 3 | "version": "0.9.2", 4 | "license": "MIT", 5 | "files": [ 6 | "dist-*/", 7 | "bin/" 8 | ], 9 | "pika": true, 10 | "sideEffects": false, 11 | "dependencies": {}, 12 | "devDependencies": { 13 | "@pika/pack": "^0.5.0", 14 | "@pika/plugin-build-node": "^0.9.2", 15 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 16 | "@types/node": "^10.12.18", 17 | "typescript": "^3.0.0" 18 | }, 19 | "publishConfig": { 20 | "access": "public" 21 | }, 22 | "source": "dist-src/index.js", 23 | "types": "dist-types/index.d.ts", 24 | "main": "dist-node/index.js" 25 | } 26 | -------------------------------------------------------------------------------- /packages/babel-plugin-esm-import-rewrite/src/index.ts: -------------------------------------------------------------------------------- 1 | import nodeFs from 'fs'; 2 | import url from 'url'; 3 | import nodePath from 'path'; 4 | import {validateDynamicImportArguments} from './validate-specifier.js'; 5 | 6 | const BareIdentifierFormat = /^((?:@[^\/]+\/)?[^\/]+)(\/.*)?$/; 7 | 8 | export default function transform({}): any { 9 | function rewriteImport(specifier, {opts, file}) { 10 | const {deps, addExtensions} = opts; 11 | try { 12 | url.parse(specifier); 13 | } catch (err) { 14 | return; 15 | } 16 | // URL w/o protocol 17 | if (specifier.substr(0, 2) === '//') { 18 | return; // Leave it alone 19 | } 20 | 21 | // Local path 22 | if (['.', '/'].indexOf(specifier.charAt(0)) >= 0) { 23 | if (addExtensions) { 24 | const extname = nodePath.extname(specifier); 25 | if (extname === '.js') { 26 | return; 27 | } 28 | if (extname) { 29 | console.warn('Unexpected file extension:', specifier); 30 | return; 31 | } 32 | const resolvedPath = nodePath.resolve(nodePath.dirname(file.opts.filename), specifier); 33 | try { 34 | const stat = nodeFs.lstatSync(resolvedPath); 35 | if (stat.isDirectory()) { 36 | return specifier + '/index.js'; 37 | } 38 | } catch (err) { 39 | // do nothing 40 | } 41 | return specifier + '.js'; 42 | } 43 | return; 44 | } 45 | 46 | // A 'bare' identifier 47 | const match = BareIdentifierFormat.exec(specifier); 48 | if (deps && match) { 49 | const packageName = match[1]; 50 | // const file = match[2] || ''; 51 | return deps[packageName]; 52 | } 53 | } 54 | 55 | return { 56 | visitor: { 57 | 'ImportDeclaration|ExportNamedDeclaration|ExportAllDeclaration'(path, {opts, file}) { 58 | if (!path.node.source) { 59 | return; 60 | } 61 | const rewrittenSpecifier = rewriteImport(path.node.source.value, {opts, file}); 62 | if (rewrittenSpecifier) { 63 | path.node.source.value = rewrittenSpecifier; 64 | } 65 | }, 66 | Import(path, {opts, file}) { 67 | const errors = validateDynamicImportArguments(path); 68 | if (errors.size > 0) { 69 | return; 70 | } 71 | 72 | const [importPath] = path.parent.arguments; 73 | const rewrittenSpecifier = rewriteImport(importPath.value, {opts, file}); 74 | if (rewrittenSpecifier) { 75 | importPath.value = rewrittenSpecifier; 76 | } 77 | }, 78 | }, 79 | }; 80 | } 81 | -------------------------------------------------------------------------------- /packages/babel-plugin-esm-import-rewrite/src/validate-specifier.ts: -------------------------------------------------------------------------------- 1 | function getLineCol(node: any): string { 2 | const loc = node.loc.start; 3 | // return chalk.dim(`[${loc.line}:${loc.column}]`); 4 | return `[${loc.line}:${loc.column}]`; 5 | } 6 | 7 | export function validateDynamicImportArguments(path): Set { 8 | if (path.parent.arguments.length !== 1) { 9 | return new Set([ 10 | `${getLineCol(path.node)} "\`import()\` only accepts 1 argument, but got ${path.parent.arguments.length}`, 11 | ]); 12 | } 13 | const [argNode] = path.parent.arguments; 14 | if (argNode.type !== 'StringLiteral') { 15 | return new Set([ 16 | `${getLineCol( 17 | path.node, 18 | )} Pika expects strings as \`import()\` arguments. Treating this as an absolute file path.`, 19 | ]); 20 | } 21 | return new Set(); 22 | } 23 | -------------------------------------------------------------------------------- /packages/babel-plugin-esm-import-rewrite/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["src"], 4 | "exclude": ["node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/plugin-build-deno/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-build-deno 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds a TypeScript distribution to your package, built to run on [Deno](https://deno.land/). 5 | 6 | **Note:** The plugin is currently only smart enough to build a distribution from source that would already run on Deno. Converting npm imports to run on Deno is coming soon. 7 | 8 | 9 | ## Install 10 | 11 | ```sh 12 | # npm: 13 | npm install @pika/plugin-build-deno --save-dev 14 | # yarn: 15 | yarn add @pika/plugin-build-deno --dev 16 | ``` 17 | 18 | 19 | ## Usage 20 | 21 | ```json 22 | { 23 | "name": "example-package-json", 24 | "version": "1.0.0", 25 | "@pika/pack": { 26 | "pipeline": [ 27 | ["@pika/plugin-ts-standard-pkg"], 28 | ["@pika/plugin-build-deno"] 29 | ] 30 | } 31 | } 32 | ``` 33 | 34 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 35 | 36 | 37 | ## Options 38 | 39 | - `"entrypoint"` (Default: `"deno"`): Customize the package.json manifest entrypoint set by this plugin. Accepts either a string, an array of strings, or `null` to disable entrypoint. Changing this is not recommended for most usage. 40 | 41 | 42 | ## Result 43 | 44 | 1. Adds a TypeScript distribution to your built package: `dist-deno/` 45 | 2. Adds a "deno" entrypoint to your built `package.json` manifest. 46 | 47 | > *Note:* This package is still experimental, and the built distribution is more or less a copy of your TypeScript source code. We'd love some help making this smarter (for example: rewriting npm package `import` statements from package names to unpkg.com URLs). -------------------------------------------------------------------------------- /packages/plugin-build-deno/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-build-deno", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: Adds a TypeScript distribution to your package, built to run on Deno.", 5 | "license": "MIT", 6 | "main": "pkg/dist-node/index.js", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "@pika/plugin-ts-standard-pkg" 19 | ], 20 | [ 21 | "@pika/plugin-build-node" 22 | ] 23 | ] 24 | }, 25 | "scripts": { 26 | "build": "pika-pack build" 27 | }, 28 | "dependencies": { 29 | "@pika/types": "^0.9.2", 30 | "mkdirp": "^0.5.1" 31 | }, 32 | "devDependencies": { 33 | "@pika/pack": "^0.5.0", 34 | "@pika/plugin-build-node": "^0.9.2", 35 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 36 | "@types/node": "^10.12.18", 37 | "typescript": "^3.0.0" 38 | }, 39 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593" 40 | } 41 | -------------------------------------------------------------------------------- /packages/plugin-build-deno/pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-build-deno 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds a TypeScript distribution to your package, built to run on [Deno](https://deno.land/). 5 | 6 | **Note:** The plugin is currently only smart enough to build a distribution from source that would already run on Deno. Converting npm imports to run on Deno is coming soon. 7 | 8 | 9 | ## Install 10 | 11 | ```sh 12 | # npm: 13 | npm install @pika/plugin-build-deno --save-dev 14 | # yarn: 15 | yarn add @pika/plugin-build-deno --dev 16 | ``` 17 | 18 | 19 | ## Usage 20 | 21 | ```json 22 | { 23 | "name": "example-package-json", 24 | "version": "1.0.0", 25 | "@pika/pack": { 26 | "pipeline": [ 27 | ["@pika/plugin-ts-standard-pkg"], 28 | ["@pika/plugin-build-deno"] 29 | ] 30 | } 31 | } 32 | ``` 33 | 34 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 35 | 36 | 37 | ## Options 38 | 39 | - `"entrypoint"` (Default: `"deno"`): Customize the package.json manifest entrypoint set by this plugin. Accepts either a string, an array of strings, or `null` to disable entrypoint. Changing this is not recommended for most usage. 40 | 41 | 42 | ## Result 43 | 44 | 1. Adds a TypeScript distribution to your built package: `dist-deno/` 45 | 2. Adds a "deno" entrypoint to your built `package.json` manifest. 46 | 47 | > *Note:* This package is still experimental, and the built distribution is more or less a copy of your TypeScript source code. We'd love some help making this smarter (for example: rewriting npm package `import` statements from package names to unpkg.com URLs). -------------------------------------------------------------------------------- /packages/plugin-build-deno/pkg/dist-node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } 6 | 7 | var path = _interopDefault(require('path')); 8 | var fs = _interopDefault(require('fs')); 9 | var util = _interopDefault(require('util')); 10 | var glob = _interopDefault(require('glob')); 11 | var mkdirp = _interopDefault(require('mkdirp')); 12 | 13 | const DEFAULT_ENTRYPOINT = 'deno'; 14 | async function manifest(manifest, { 15 | cwd, 16 | options 17 | }) { 18 | const pathToTsconfig = path.join(cwd, 'tsconfig.json'); 19 | 20 | if (!fs.existsSync(pathToTsconfig)) { 21 | return; 22 | } 23 | 24 | if (options.entrypoint !== null) { 25 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 26 | 27 | if (typeof keys === 'string') { 28 | keys = [keys]; 29 | } 30 | 31 | for (const key of keys) { 32 | manifest[key] = manifest[key] || 'dist-deno/index.ts'; 33 | } 34 | } 35 | } 36 | async function build({ 37 | cwd, 38 | out, 39 | options 40 | }) { 41 | const pathToTsconfig = path.join(cwd, 'tsconfig.json'); 42 | 43 | if (!fs.existsSync(pathToTsconfig)) { 44 | return; 45 | } 46 | 47 | const files = await util.promisify(glob)(`src/**/*`, { 48 | cwd, 49 | nodir: true, 50 | absolute: true, 51 | ignore: (options.exclude || []).map(g => path.join('src', g)) 52 | }); 53 | 54 | for (const fileAbs of files) { 55 | if (path.extname(fileAbs) !== '.ts' && path.extname(fileAbs) !== '.tsx') { 56 | continue; 57 | } 58 | 59 | const fileRel = path.relative(cwd, fileAbs); 60 | const writeToTypeScript = path.resolve(out, fileRel).replace(`${path.sep}src${path.sep}`, `${path.sep}dist-deno${path.sep}`); 61 | mkdirp.sync(path.dirname(writeToTypeScript)); 62 | fs.copyFileSync(fileAbs, writeToTypeScript); 63 | } 64 | } 65 | 66 | exports.build = build; 67 | exports.manifest = manifest; 68 | //# sourceMappingURL=index.js.map 69 | -------------------------------------------------------------------------------- /packages/plugin-build-deno/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import util from 'util'; 4 | import glob from 'glob'; 5 | import mkdirp from 'mkdirp'; 6 | const DEFAULT_ENTRYPOINT = 'deno'; 7 | export async function manifest(manifest, { cwd, options }) { 8 | const pathToTsconfig = path.join(cwd, 'tsconfig.json'); 9 | if (!fs.existsSync(pathToTsconfig)) { 10 | return; 11 | } 12 | if (options.entrypoint !== null) { 13 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 14 | if (typeof keys === 'string') { 15 | keys = [keys]; 16 | } 17 | for (const key of keys) { 18 | manifest[key] = manifest[key] || 'dist-deno/index.ts'; 19 | } 20 | } 21 | } 22 | export async function build({ cwd, out, options }) { 23 | const pathToTsconfig = path.join(cwd, 'tsconfig.json'); 24 | if (!fs.existsSync(pathToTsconfig)) { 25 | return; 26 | } 27 | const files = await util.promisify(glob)(`src/**/*`, { 28 | cwd, 29 | nodir: true, 30 | absolute: true, 31 | ignore: (options.exclude || []).map(g => path.join('src', g)), 32 | }); 33 | for (const fileAbs of files) { 34 | if (path.extname(fileAbs) !== '.ts' && path.extname(fileAbs) !== '.tsx') { 35 | continue; 36 | } 37 | const fileRel = path.relative(cwd, fileAbs); 38 | const writeToTypeScript = path 39 | .resolve(out, fileRel) 40 | .replace(`${path.sep}src${path.sep}`, `${path.sep}dist-deno${path.sep}`); 41 | mkdirp.sync(path.dirname(writeToTypeScript)); 42 | fs.copyFileSync(fileAbs, writeToTypeScript); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /packages/plugin-build-deno/pkg/dist-types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { BuilderOptions } from '@pika/types'; 2 | export declare function manifest(manifest: any, { cwd, options }: BuilderOptions): Promise; 3 | export declare function build({ cwd, out, options }: BuilderOptions): Promise; 4 | -------------------------------------------------------------------------------- /packages/plugin-build-deno/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-build-deno", 3 | "description": "A @pika/pack plugin: Adds a TypeScript distribution to your package, built to run on Deno.", 4 | "version": "0.9.2", 5 | "license": "MIT", 6 | "files": [ 7 | "dist-*/", 8 | "bin/" 9 | ], 10 | "pika": true, 11 | "sideEffects": false, 12 | "homepage": "https://www.pikapkg.com", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/pikapkg/builders.git" 16 | }, 17 | "dependencies": { 18 | "@pika/types": "^0.9.2", 19 | "mkdirp": "^0.5.1" 20 | }, 21 | "devDependencies": { 22 | "@pika/pack": "^0.5.0", 23 | "@pika/plugin-build-node": "^0.9.2", 24 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 25 | "@types/node": "^10.12.18", 26 | "typescript": "^3.0.0" 27 | }, 28 | "publishConfig": { 29 | "access": "public" 30 | }, 31 | "source": "dist-src/index.js", 32 | "types": "dist-types/index.d.ts", 33 | "main": "dist-node/index.js" 34 | } 35 | -------------------------------------------------------------------------------- /packages/plugin-build-deno/src/index.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import util from 'util'; 4 | import glob from 'glob'; 5 | import mkdirp from 'mkdirp'; 6 | import {BuilderOptions} from '@pika/types'; 7 | const DEFAULT_ENTRYPOINT = 'deno'; 8 | 9 | export async function manifest(manifest, {cwd, options}: BuilderOptions): Promise { 10 | const pathToTsconfig = path.join(cwd, 'tsconfig.json'); 11 | if (!fs.existsSync(pathToTsconfig)) { 12 | return; 13 | } 14 | if (options.entrypoint !== null) { 15 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 16 | if (typeof keys === 'string') { 17 | keys = [keys]; 18 | } 19 | for (const key of keys) { 20 | manifest[key] = manifest[key] || 'dist-deno/index.ts'; 21 | } 22 | } 23 | } 24 | 25 | export async function build({cwd, out, options}: BuilderOptions): Promise { 26 | const pathToTsconfig = path.join(cwd, 'tsconfig.json'); 27 | if (!fs.existsSync(pathToTsconfig)) { 28 | return; 29 | } 30 | 31 | const files = await util.promisify(glob)(`src/**/*`, { 32 | cwd, 33 | nodir: true, 34 | absolute: true, 35 | ignore: (options.exclude || []).map(g => path.join('src', g)), 36 | }); 37 | for (const fileAbs of files) { 38 | if (path.extname(fileAbs) !== '.ts' && path.extname(fileAbs) !== '.tsx') { 39 | continue; 40 | } 41 | const fileRel = path.relative(cwd, fileAbs); 42 | const writeToTypeScript = path 43 | .resolve(out, fileRel) 44 | .replace(`${path.sep}src${path.sep}`, `${path.sep}dist-deno${path.sep}`); 45 | mkdirp.sync(path.dirname(writeToTypeScript)); 46 | fs.copyFileSync(fileAbs, writeToTypeScript); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /packages/plugin-build-deno/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["src"], 4 | "exclude": ["node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/plugin-build-node/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-build-node 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds a Node.js distribution to your package, built & optimized to run on [Node.js](https://nodejs.org/). If no other distribution is included with your package, many other tools & bundlers can understand this format as well. 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-build-node --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-build-node --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```json 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-standard-pkg"], 26 | ["@pika/plugin-build-node", {}] 27 | ] 28 | } 29 | } 30 | ``` 31 | 32 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 33 | 34 | 35 | ## Options 36 | 37 | - `"sourcemap"` (Default: `"true"`): Adds a [source map](https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) for this build. 38 | - `"minNodeVersion"` (Default: `"10"`): This plugin will build your package for the current minimum [Node.js LTS](https://github.com/nodejs/Release) major version. This option allows you to target later versions of Node.js only. 39 | - `"entrypoint"` (Default: `"main"`): Customize the package.json manifest entrypoint set by this plugin. Accepts either a string, an array of strings, or `null` to disable entrypoint. Changing this is not recommended for most usage. 40 | 41 | 42 | ## Result 43 | 44 | 1. Adds a Node.js distribution to your built package: `dist-node/index.js` 45 | 1. Common.js (CJS) Module Syntax 46 | 1. Transpiled to run on Node.js LTS (Currently, supports Node.js version v10+) 47 | 1. Adds a "main" entrypoint to your built `package.json` manifest. 48 | -------------------------------------------------------------------------------- /packages/plugin-build-node/custom-types/babel-plugin-dynamic-import-node-babel-7.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'babel-plugin-dynamic-import-node-babel-7' { 2 | export default function(): void; 3 | } 4 | -------------------------------------------------------------------------------- /packages/plugin-build-node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-build-node", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: Adds a Node.js distribution to your package, built & optimized to run on Node.js.", 5 | "license": "MIT", 6 | "main": "pkg/dist-node/index.js", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "@pika/plugin-ts-standard-pkg" 19 | ], 20 | [ 21 | "./pkg" 22 | ] 23 | ] 24 | }, 25 | "scripts": { 26 | "build": "pika-pack build" 27 | }, 28 | "dependencies": { 29 | "@babel/core": "^7.0.0", 30 | "@babel/plugin-syntax-dynamic-import": "^7.2.0", 31 | "@babel/plugin-syntax-import-meta": "^7.2.0", 32 | "@babel/preset-env": "^7.2.3", 33 | "@pika/types": "^0.9.2", 34 | "babel-plugin-dynamic-import-node-babel-7": "^2.0.7", 35 | "builtin-modules": "^3.0.0", 36 | "rollup": "^2.3.0", 37 | "rollup-plugin-babel": "^4.3.0" 38 | }, 39 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593", 40 | "devDependencies": { 41 | "@pika/pack": "^0.5.0", 42 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 43 | "@types/node": "^10.12.18", 44 | "typescript": "^3.0.0" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /packages/plugin-build-node/pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-build-node 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds a Node.js distribution to your package, built & optimized to run on [Node.js](https://nodejs.org/). If no other distribution is included with your package, many other tools & bundlers can understand this format as well. 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-build-node --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-build-node --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```json 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-standard-pkg"], 26 | ["@pika/plugin-build-node", {}] 27 | ] 28 | } 29 | } 30 | ``` 31 | 32 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 33 | 34 | 35 | ## Options 36 | 37 | - `"sourcemap"` (Default: `"true"`): Adds a [source map](https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) for this build. 38 | - `"minNodeVersion"` (Default: `"8"`): This plugin will build your package for the current minimum [Node.js LTS](https://github.com/nodejs/Release) major version. This option allows you to target later versions of Node.js only. 39 | - `"entrypoint"` (Default: `"main"`): Customize the package.json manifest entrypoint set by this plugin. Accepts either a string, an array of strings, or `null` to disable entrypoint. Changing this is not recommended for most usage. 40 | 41 | 42 | ## Result 43 | 44 | 1. Adds a Node.js distribution to your built package: `dist-node/index.js` 45 | 1. Common.js (CJS) Module Syntax 46 | 1. Transpiled to run on Node.js LTS (Currently, supports Node.js version v6+) 47 | 1. Adds a "main" entrypoint to your built `package.json` manifest. 48 | -------------------------------------------------------------------------------- /packages/plugin-build-node/pkg/dist-node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } 6 | 7 | var fs = _interopDefault(require('fs')); 8 | var path = _interopDefault(require('path')); 9 | var babelPluginDynamicImportSyntax = _interopDefault(require('@babel/plugin-syntax-dynamic-import')); 10 | var babelPluginImportMetaSyntax = _interopDefault(require('@babel/plugin-syntax-import-meta')); 11 | var babelPresetEnv = _interopDefault(require('@babel/preset-env')); 12 | var babelPluginDynamicImport = _interopDefault(require('babel-plugin-dynamic-import-node-babel-7')); 13 | var builtinModules = _interopDefault(require('builtin-modules')); 14 | var rollupBabel = _interopDefault(require('rollup-plugin-babel')); 15 | var types = require('@pika/types'); 16 | var rollup = require('rollup'); 17 | 18 | const DEFAULT_ENTRYPOINT = 'main'; 19 | const DEFAULT_MIN_NODE_VERSION = '8'; 20 | function manifest(manifest, { 21 | options 22 | }) { 23 | if (options.entrypoint !== null) { 24 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 25 | 26 | if (typeof keys === 'string') { 27 | keys = [keys]; 28 | } 29 | 30 | for (const key of keys) { 31 | manifest[key] = manifest[key] || 'dist-node/index.js'; 32 | } 33 | } 34 | } 35 | async function beforeJob({ 36 | out 37 | }) { 38 | const srcDirectory = path.join(out, 'dist-src/'); 39 | 40 | if (!fs.existsSync(srcDirectory)) { 41 | throw new types.MessageError('"dist-src/" does not exist, or was not yet created in the pipeline.'); 42 | } 43 | 44 | const srcEntrypoint = path.join(out, 'dist-src/index.js'); 45 | 46 | if (!fs.existsSync(srcEntrypoint)) { 47 | throw new types.MessageError('"dist-src/index.js" is the expected standard entrypoint, but it does not exist.'); 48 | } 49 | } 50 | async function build({ 51 | out, 52 | reporter, 53 | options 54 | }) { 55 | const writeToNode = path.join(out, 'dist-node', 'index.js'); // TODO: KEEP FIXING THIS, 56 | 57 | const result = await rollup.rollup({ 58 | input: path.join(out, 'dist-src/index.js'), 59 | external: builtinModules, 60 | plugins: [rollupBabel({ 61 | babelrc: false, 62 | compact: false, 63 | presets: [[babelPresetEnv, { 64 | modules: false, 65 | targets: { 66 | node: options.minNodeVersion || DEFAULT_MIN_NODE_VERSION 67 | }, 68 | spec: true 69 | }]], 70 | plugins: [babelPluginDynamicImport, babelPluginDynamicImportSyntax, babelPluginImportMetaSyntax] 71 | })], 72 | onwarn: (warning, defaultOnWarnHandler) => { 73 | // Unresolved external imports are expected 74 | if (warning.code === 'UNRESOLVED_IMPORT' && !(warning.source.startsWith('./') || warning.source.startsWith('../'))) { 75 | return; 76 | } 77 | 78 | defaultOnWarnHandler(warning); 79 | } 80 | }); 81 | await result.write({ 82 | file: writeToNode, 83 | format: 'cjs', 84 | exports: 'named', 85 | sourcemap: options.sourcemap === undefined ? true : options.sourcemap 86 | }); 87 | reporter.created(writeToNode, 'main'); 88 | } 89 | 90 | exports.beforeJob = beforeJob; 91 | exports.build = build; 92 | exports.manifest = manifest; 93 | //# sourceMappingURL=index.js.map 94 | -------------------------------------------------------------------------------- /packages/plugin-build-node/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import path from 'path'; 3 | import babelPluginDynamicImportSyntax from '@babel/plugin-syntax-dynamic-import'; 4 | import babelPluginImportMetaSyntax from '@babel/plugin-syntax-import-meta'; 5 | import babelPresetEnv from '@babel/preset-env'; 6 | import babelPluginDynamicImport from 'babel-plugin-dynamic-import-node-babel-7'; 7 | import builtinModules from 'builtin-modules'; 8 | import rollupBabel from 'rollup-plugin-babel'; 9 | import { MessageError } from '@pika/types'; 10 | import { rollup } from 'rollup'; 11 | const DEFAULT_ENTRYPOINT = 'main'; 12 | const DEFAULT_MIN_NODE_VERSION = '8'; 13 | export function manifest(manifest, { options }) { 14 | if (options.entrypoint !== null) { 15 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 16 | if (typeof keys === 'string') { 17 | keys = [keys]; 18 | } 19 | for (const key of keys) { 20 | manifest[key] = manifest[key] || 'dist-node/index.js'; 21 | } 22 | } 23 | } 24 | export async function beforeJob({ out }) { 25 | const srcDirectory = path.join(out, 'dist-src/'); 26 | if (!fs.existsSync(srcDirectory)) { 27 | throw new MessageError('"dist-src/" does not exist, or was not yet created in the pipeline.'); 28 | } 29 | const srcEntrypoint = path.join(out, 'dist-src/index.js'); 30 | if (!fs.existsSync(srcEntrypoint)) { 31 | throw new MessageError('"dist-src/index.js" is the expected standard entrypoint, but it does not exist.'); 32 | } 33 | } 34 | export async function build({ out, reporter, options }) { 35 | const writeToNode = path.join(out, 'dist-node', 'index.js'); 36 | // TODO: KEEP FIXING THIS, 37 | const result = await rollup({ 38 | input: path.join(out, 'dist-src/index.js'), 39 | external: builtinModules, 40 | plugins: [ 41 | rollupBabel({ 42 | babelrc: false, 43 | compact: false, 44 | presets: [ 45 | [ 46 | babelPresetEnv, 47 | { 48 | modules: false, 49 | targets: { node: options.minNodeVersion || DEFAULT_MIN_NODE_VERSION }, 50 | spec: true, 51 | }, 52 | ], 53 | ], 54 | plugins: [babelPluginDynamicImport, babelPluginDynamicImportSyntax, babelPluginImportMetaSyntax], 55 | }), 56 | ], 57 | onwarn: ((warning, defaultOnWarnHandler) => { 58 | // Unresolved external imports are expected 59 | if (warning.code === 'UNRESOLVED_IMPORT' && 60 | !(warning.source.startsWith('./') || warning.source.startsWith('../'))) { 61 | return; 62 | } 63 | defaultOnWarnHandler(warning); 64 | }), 65 | }); 66 | await result.write({ 67 | file: writeToNode, 68 | format: 'cjs', 69 | exports: 'named', 70 | sourcemap: options.sourcemap === undefined ? true : options.sourcemap, 71 | }); 72 | reporter.created(writeToNode, 'main'); 73 | } 74 | -------------------------------------------------------------------------------- /packages/plugin-build-node/pkg/dist-types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { BuilderOptions } from '@pika/types'; 2 | export declare function manifest(manifest: any, { options }: BuilderOptions): void; 3 | export declare function beforeJob({ out }: BuilderOptions): Promise; 4 | export declare function build({ out, reporter, options }: BuilderOptions): Promise; 5 | -------------------------------------------------------------------------------- /packages/plugin-build-node/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-build-node", 3 | "description": "A @pika/pack plugin: Adds a Node.js distribution to your package, built & optimized to run on Node.js.", 4 | "version": "0.9.2", 5 | "license": "MIT", 6 | "files": [ 7 | "dist-*/", 8 | "bin/" 9 | ], 10 | "pika": true, 11 | "sideEffects": false, 12 | "homepage": "https://www.pikapkg.com", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/pikapkg/builders.git" 16 | }, 17 | "dependencies": { 18 | "@babel/core": "^7.0.0", 19 | "@babel/plugin-syntax-dynamic-import": "^7.2.0", 20 | "@babel/plugin-syntax-import-meta": "^7.2.0", 21 | "@babel/preset-env": "^7.2.3", 22 | "@pika/types": "^0.9.2", 23 | "babel-plugin-dynamic-import-node-babel-7": "^2.0.7", 24 | "builtin-modules": "^3.0.0", 25 | "rollup": "^2.3.0", 26 | "rollup-plugin-babel": "^4.3.0" 27 | }, 28 | "devDependencies": { 29 | "@pika/pack": "^0.5.0", 30 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 31 | "@types/node": "^10.12.18", 32 | "typescript": "^3.0.0" 33 | }, 34 | "publishConfig": { 35 | "access": "public" 36 | }, 37 | "source": "dist-src/index.js", 38 | "types": "dist-types/index.d.ts", 39 | "main": "dist-node/index.js" 40 | } 41 | -------------------------------------------------------------------------------- /packages/plugin-build-node/src/index.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import path from 'path'; 3 | import babelPluginDynamicImportSyntax from '@babel/plugin-syntax-dynamic-import'; 4 | import babelPluginImportMetaSyntax from '@babel/plugin-syntax-import-meta'; 5 | import babelPresetEnv from '@babel/preset-env'; 6 | import babelPluginDynamicImport from 'babel-plugin-dynamic-import-node-babel-7'; 7 | import builtinModules from 'builtin-modules'; 8 | import rollupBabel from 'rollup-plugin-babel'; 9 | import {BuilderOptions, MessageError} from '@pika/types'; 10 | import {rollup} from 'rollup'; 11 | 12 | const DEFAULT_ENTRYPOINT = 'main'; 13 | const DEFAULT_MIN_NODE_VERSION = '10'; 14 | 15 | export function manifest(manifest, {options}: BuilderOptions) { 16 | if (options.entrypoint !== null) { 17 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 18 | if (typeof keys === 'string') { 19 | keys = [keys]; 20 | } 21 | for (const key of keys) { 22 | manifest[key] = manifest[key] || 'dist-node/index.js'; 23 | } 24 | } 25 | } 26 | 27 | export async function beforeJob({out}: BuilderOptions) { 28 | const srcDirectory = path.join(out, 'dist-src/'); 29 | if (!fs.existsSync(srcDirectory)) { 30 | throw new MessageError('"dist-src/" does not exist, or was not yet created in the pipeline.'); 31 | } 32 | const srcEntrypoint = path.join(out, 'dist-src/index.js'); 33 | if (!fs.existsSync(srcEntrypoint)) { 34 | throw new MessageError('"dist-src/index.js" is the expected standard entrypoint, but it does not exist.'); 35 | } 36 | } 37 | 38 | export async function build({out, reporter, options}: BuilderOptions): Promise { 39 | const writeToNode = path.join(out, 'dist-node', 'index.js'); 40 | 41 | // TODO: KEEP FIXING THIS, 42 | const result = await rollup({ 43 | input: path.join(out, 'dist-src/index.js'), 44 | external: builtinModules as string[], 45 | plugins: [ 46 | rollupBabel({ 47 | babelrc: false, 48 | compact: false, 49 | presets: [ 50 | [ 51 | babelPresetEnv, 52 | { 53 | modules: false, 54 | targets: {node: options.minNodeVersion || DEFAULT_MIN_NODE_VERSION}, 55 | spec: true, 56 | }, 57 | ], 58 | ], 59 | plugins: [babelPluginDynamicImport, babelPluginDynamicImportSyntax, babelPluginImportMetaSyntax], 60 | }), 61 | ], 62 | onwarn: ((warning, defaultOnWarnHandler) => { 63 | // Unresolved external imports are expected 64 | if ( 65 | warning.code === 'UNRESOLVED_IMPORT' && 66 | !(warning.source.startsWith('./') || warning.source.startsWith('../')) 67 | ) { 68 | return; 69 | } 70 | defaultOnWarnHandler(warning); 71 | }) as any, 72 | }); 73 | 74 | await result.write({ 75 | file: writeToNode, 76 | format: 'cjs', 77 | exports: 'named', 78 | sourcemap: options.sourcemap === undefined ? true : options.sourcemap, 79 | }); 80 | reporter.created(writeToNode, 'main'); 81 | } 82 | -------------------------------------------------------------------------------- /packages/plugin-build-node/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["src"], 4 | "exclude": ["node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/plugin-build-types/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-build-types 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Automatically adds TypeScript type definitions to your package build. 5 | 6 | *Note: This plugin is not needed if you are already writing TypeScript and using the [ts-standard-pkg](/packages/plugin-ts-standard-pkg) plugin.* 7 | 8 | 9 | ## Install 10 | 11 | ```sh 12 | # npm: 13 | npm install @pika/plugin-build-types --save-dev 14 | # yarn: 15 | yarn add @pika/plugin-build-types --dev 16 | ``` 17 | 18 | 19 | ## Usage 20 | 21 | ```json 22 | { 23 | "name": "example-package-json", 24 | "version": "1.0.0", 25 | "@pika/pack": { 26 | "pipeline": [ 27 | ["@pika/plugin-standard-pkg"], 28 | ["@pika/plugin-build-types"] 29 | ] 30 | } 31 | } 32 | ``` 33 | 34 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 35 | 36 | 37 | ## Options 38 | 39 | - `"tsconfig"`: The relative path to the `tsconfig.json` config file to use. Defaults to the top-level project TypeScript config file, if one exists. 40 | - `"args"`: Optional, an array of additional arguments for tsc. Example: `["--build"]` 41 | - `"entrypoint"` (Default: `"types"`): Customize the package.json manifest entrypoint set by this plugin. Accepts either a string, an array of strings, or `null` to disable entrypoint. Changing this is not recommended for most usage. 42 | 43 | 44 | ## Result 45 | 46 | 1. Adds or generates TypeScript definitions for your package build: `dist-types/` 47 | - If your package is written in TypeScript: Types are automatically generated from your source. 48 | - If your package already includes custom-written type definitions: These files are automatically copied into your package build. 49 | - Otherwise: Automatically generate definitions from your JavaScript source. *(Note that this currently requires that you include `@pika/plugin-build-node` or some other Node.js build earlier in the pipeline.)* 50 | 2. Adds a "types" entrypoint to your built `package.json` manifest. 51 | -------------------------------------------------------------------------------- /packages/plugin-build-types/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-build-types", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: Adds TypeScript type definitions to your package build.", 5 | "license": "MIT", 6 | "main": "pkg/dist-node/index.js", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "@pika/plugin-ts-standard-pkg" 19 | ], 20 | [ 21 | "@pika/plugin-build-node" 22 | ] 23 | ] 24 | }, 25 | "scripts": { 26 | "build": "pika-pack build" 27 | }, 28 | "dependencies": { 29 | "@pika/types": "^0.9.2", 30 | "execa": "^2.0.0", 31 | "mkdirp": "^0.5.1", 32 | "typescript": "^3.7.0" 33 | }, 34 | "devDependencies": { 35 | "@pika/pack": "^0.5.0", 36 | "@pika/plugin-build-node": "^0.9.2", 37 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 38 | "@types/node": "^10.12.18" 39 | }, 40 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593" 41 | } 42 | -------------------------------------------------------------------------------- /packages/plugin-build-types/pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-build-types 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Automatically adds TypeScript type definitions to your package build. 5 | 6 | *Note: This plugin is not needed if you are already writing TypeScript and using the [ts-standard-pkg](/packages/plugin-ts-standard-pkg) plugin.* 7 | 8 | 9 | ## Install 10 | 11 | ```sh 12 | # npm: 13 | npm install @pika/plugin-build-types --save-dev 14 | # yarn: 15 | yarn add @pika/plugin-build-types --dev 16 | ``` 17 | 18 | 19 | ## Usage 20 | 21 | ```json 22 | { 23 | "name": "example-package-json", 24 | "version": "1.0.0", 25 | "@pika/pack": { 26 | "pipeline": [ 27 | ["@pika/plugin-standard-pkg"], 28 | ["@pika/plugin-build-types"] 29 | ] 30 | } 31 | } 32 | ``` 33 | 34 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 35 | 36 | 37 | ## Options 38 | 39 | - `"tsconfig"`: The relative path to the `tsconfig.json` config file to use. Defaults to the top-level project TypeScript config file, if one exists. 40 | - `"args"`: Optional, an array of additional arguments for tsc. Example: `["--build"]` 41 | - `"entrypoint"` (Default: `"types"`): Customize the package.json manifest entrypoint set by this plugin. Accepts either a string, an array of strings, or `null` to disable entrypoint. Changing this is not recommended for most usage. 42 | 43 | 44 | ## Result 45 | 46 | 1. Adds or generates TypeScript definitions for your package build: `dist-types/` 47 | - If your package is written in TypeScript: Types are automatically generated from your source. 48 | - If your package already includes custom-written type definitions: These files are automatically copied into your package build. 49 | - Otherwise: Automatically generate definitions from your JavaScript source. *(Note that this currently requires that you include `@pika/plugin-build-node` or some other Node.js build earlier in the pipeline.)* 50 | 2. Adds a "types" entrypoint to your built `package.json` manifest. 51 | -------------------------------------------------------------------------------- /packages/plugin-build-types/pkg/dist-node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } 6 | 7 | var path = _interopDefault(require('path')); 8 | var fs = _interopDefault(require('fs')); 9 | var mkdirp = _interopDefault(require('mkdirp')); 10 | var execa = _interopDefault(require('execa')); 11 | var types = require('@pika/types'); 12 | 13 | const DEFAULT_ENTRYPOINT = 'types'; 14 | 15 | function getTsConfigPath(options, cwd) { 16 | return path.resolve(cwd, options.tsconfig || 'tsconfig.json'); 17 | } 18 | 19 | function getTscBin(cwd) { 20 | try { 21 | return require.resolve('typescript/bin/tsc', { 22 | paths: [cwd] 23 | }); 24 | } catch (err) { 25 | // ignore err 26 | return null; 27 | } 28 | } 29 | 30 | function manifest(manifest, { 31 | options 32 | }) { 33 | if (options.entrypoint !== null) { 34 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 35 | 36 | if (typeof keys === 'string') { 37 | keys = [keys]; 38 | } 39 | 40 | for (const key of keys) { 41 | manifest[key] = manifest[key] || 'dist-types/index.d.ts'; 42 | } 43 | } 44 | } 45 | async function beforeBuild({ 46 | options, 47 | cwd 48 | }) { 49 | const tsConfigPath = getTsConfigPath(options, cwd); 50 | 51 | if (options.tsconfig && !fs.existsSync(tsConfigPath)) { 52 | throw new types.MessageError(`"${tsConfigPath}" file does not exist.`); 53 | } 54 | } 55 | async function build({ 56 | cwd, 57 | out, 58 | options, 59 | reporter 60 | }) { 61 | await (async () => { 62 | const writeToTypings = path.join(out, 'dist-types/index.d.ts'); 63 | const importAsNode = path.join(out, 'dist-node', 'index.js'); 64 | 65 | if (fs.existsSync(path.join(cwd, 'index.d.ts'))) { 66 | mkdirp.sync(path.dirname(writeToTypings)); 67 | fs.copyFileSync(path.join(cwd, 'index.d.ts'), writeToTypings); 68 | return; 69 | } 70 | 71 | if (fs.existsSync(path.join(cwd, 'src', 'index.d.ts'))) { 72 | mkdirp.sync(path.dirname(writeToTypings)); 73 | fs.copyFileSync(path.join(cwd, 'src', 'index.d.ts'), writeToTypings); 74 | return; 75 | } 76 | 77 | const tsConfigPath = getTsConfigPath(options, cwd); 78 | const tscBin = getTscBin(cwd); 79 | const additionalArgs = options.args || []; 80 | 81 | if (!tscBin || !fs.existsSync(tsConfigPath)) { 82 | reporter.warning(`No manual type definitions found. 83 | 84 | To generate types automatically: 85 | 1. Install TypeScript as a "dev" dependency in your project: \`npm install --save-dev typescript@^3.7.0\` 86 | 2. Add a basic tsconfig.json file to your project: \`{"include": ["src"]}\` 87 | 3. Re-run this build. 88 | `); 89 | return; 90 | } 91 | 92 | reporter.info('no manual type definitions found, auto-generating...'); 93 | await execa(tscBin, ['-d', '--allowJs', '--emitDeclarationOnly', '--declarationMap', 'false', '--project', tsConfigPath, '--declarationDir', path.join(out, 'dist-types/'), ...additionalArgs], { 94 | cwd 95 | }); 96 | })(); 97 | reporter.created(path.join(out, 'dist-types', 'index.d.ts'), 'types'); 98 | } 99 | 100 | exports.beforeBuild = beforeBuild; 101 | exports.build = build; 102 | exports.manifest = manifest; 103 | //# sourceMappingURL=index.js.map 104 | -------------------------------------------------------------------------------- /packages/plugin-build-types/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import mkdirp from 'mkdirp'; 4 | import execa from 'execa'; 5 | import { MessageError } from '@pika/types'; 6 | const DEFAULT_ENTRYPOINT = 'types'; 7 | function getTsConfigPath(options, cwd) { 8 | return path.resolve(cwd, options.tsconfig || 'tsconfig.json'); 9 | } 10 | function getTscBin(cwd) { 11 | try { 12 | return require.resolve('typescript/bin/tsc', { paths: [cwd] }); 13 | } 14 | catch (err) { 15 | // ignore err 16 | return null; 17 | } 18 | } 19 | export function manifest(manifest, { options }) { 20 | if (options.entrypoint !== null) { 21 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 22 | if (typeof keys === 'string') { 23 | keys = [keys]; 24 | } 25 | for (const key of keys) { 26 | manifest[key] = manifest[key] || 'dist-types/index.d.ts'; 27 | } 28 | } 29 | } 30 | export async function beforeBuild({ options, cwd }) { 31 | const tsConfigPath = getTsConfigPath(options, cwd); 32 | if (options.tsconfig && !fs.existsSync(tsConfigPath)) { 33 | throw new MessageError(`"${tsConfigPath}" file does not exist.`); 34 | } 35 | } 36 | export async function build({ cwd, out, options, reporter }) { 37 | await (async () => { 38 | const writeToTypings = path.join(out, 'dist-types/index.d.ts'); 39 | const importAsNode = path.join(out, 'dist-node', 'index.js'); 40 | if (fs.existsSync(path.join(cwd, 'index.d.ts'))) { 41 | mkdirp.sync(path.dirname(writeToTypings)); 42 | fs.copyFileSync(path.join(cwd, 'index.d.ts'), writeToTypings); 43 | return; 44 | } 45 | if (fs.existsSync(path.join(cwd, 'src', 'index.d.ts'))) { 46 | mkdirp.sync(path.dirname(writeToTypings)); 47 | fs.copyFileSync(path.join(cwd, 'src', 'index.d.ts'), writeToTypings); 48 | return; 49 | } 50 | const tsConfigPath = getTsConfigPath(options, cwd); 51 | const tscBin = getTscBin(cwd); 52 | const additionalArgs = options.args || []; 53 | if (!tscBin || !fs.existsSync(tsConfigPath)) { 54 | reporter.warning(`No manual type definitions found. 55 | 56 | To generate types automatically: 57 | 1. Install TypeScript as a "dev" dependency in your project: \`npm install --save-dev typescript@^3.7.0\` 58 | 2. Add a basic tsconfig.json file to your project: \`{"include": ["src"]}\` 59 | 3. Re-run this build. 60 | `); 61 | return; 62 | } 63 | reporter.info('no manual type definitions found, auto-generating...'); 64 | await execa(tscBin, [ 65 | '-d', 66 | '--allowJs', 67 | '--emitDeclarationOnly', 68 | '--declarationMap', 69 | 'false', 70 | '--project', 71 | tsConfigPath, 72 | '--declarationDir', 73 | path.join(out, 'dist-types/'), 74 | ...additionalArgs, 75 | ], { cwd }); 76 | })(); 77 | reporter.created(path.join(out, 'dist-types', 'index.d.ts'), 'types'); 78 | } 79 | -------------------------------------------------------------------------------- /packages/plugin-build-types/pkg/dist-types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { BuilderOptions } from '@pika/types'; 2 | export declare function manifest(manifest: any, { options }: BuilderOptions): void; 3 | export declare function beforeBuild({ options, cwd }: BuilderOptions): Promise; 4 | export declare function build({ cwd, out, options, reporter }: BuilderOptions): Promise; 5 | -------------------------------------------------------------------------------- /packages/plugin-build-types/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-build-types", 3 | "description": "A @pika/pack plugin: Adds TypeScript type definitions to your package build.", 4 | "version": "0.9.2", 5 | "license": "MIT", 6 | "files": [ 7 | "dist-*/", 8 | "bin/" 9 | ], 10 | "pika": true, 11 | "sideEffects": false, 12 | "homepage": "https://www.pikapkg.com", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/pikapkg/builders.git" 16 | }, 17 | "dependencies": { 18 | "@pika/types": "^0.9.2", 19 | "execa": "^2.0.0", 20 | "mkdirp": "^0.5.1", 21 | "typescript": "^3.7.0" 22 | }, 23 | "devDependencies": { 24 | "@pika/pack": "^0.5.0", 25 | "@pika/plugin-build-node": "^0.9.2", 26 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 27 | "@types/node": "^10.12.18" 28 | }, 29 | "publishConfig": { 30 | "access": "public" 31 | }, 32 | "source": "dist-src/index.js", 33 | "types": "dist-types/index.d.ts", 34 | "main": "dist-node/index.js" 35 | } 36 | -------------------------------------------------------------------------------- /packages/plugin-build-types/src/index.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import mkdirp from 'mkdirp'; 4 | import execa from 'execa'; 5 | import {BuilderOptions, MessageError} from '@pika/types'; 6 | const DEFAULT_ENTRYPOINT = 'types'; 7 | 8 | function getTsConfigPath(options, cwd) { 9 | return path.resolve(cwd, options.tsconfig || 'tsconfig.json'); 10 | } 11 | 12 | function getTscBin(cwd) { 13 | try { 14 | return require.resolve('typescript/bin/tsc', {paths: [cwd]}); 15 | } catch (err) { 16 | // ignore err 17 | return null; 18 | } 19 | } 20 | 21 | export function manifest(manifest, {options}: BuilderOptions) { 22 | if (options.entrypoint !== null) { 23 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 24 | if (typeof keys === 'string') { 25 | keys = [keys]; 26 | } 27 | for (const key of keys) { 28 | manifest[key] = manifest[key] || 'dist-types/index.d.ts'; 29 | } 30 | } 31 | } 32 | 33 | export async function beforeBuild({options, cwd}: BuilderOptions) { 34 | const tsConfigPath = getTsConfigPath(options, cwd); 35 | if (options.tsconfig && !fs.existsSync(tsConfigPath)) { 36 | throw new MessageError(`"${tsConfigPath}" file does not exist.`); 37 | } 38 | } 39 | 40 | export async function build({cwd, out, options, reporter}: BuilderOptions): Promise { 41 | await (async () => { 42 | const writeToTypings = path.join(out, 'dist-types/index.d.ts'); 43 | const importAsNode = path.join(out, 'dist-node', 'index.js'); 44 | 45 | if (fs.existsSync(path.join(cwd, 'index.d.ts'))) { 46 | mkdirp.sync(path.dirname(writeToTypings)); 47 | fs.copyFileSync(path.join(cwd, 'index.d.ts'), writeToTypings); 48 | return; 49 | } 50 | if (fs.existsSync(path.join(cwd, 'src', 'index.d.ts'))) { 51 | mkdirp.sync(path.dirname(writeToTypings)); 52 | fs.copyFileSync(path.join(cwd, 'src', 'index.d.ts'), writeToTypings); 53 | return; 54 | } 55 | 56 | const tsConfigPath = getTsConfigPath(options, cwd); 57 | const tscBin = getTscBin(cwd); 58 | const additionalArgs = options.args || []; 59 | if (!tscBin || !fs.existsSync(tsConfigPath)) { 60 | reporter.warning( 61 | `No manual type definitions found. 62 | 63 | To generate types automatically: 64 | 1. Install TypeScript as a "dev" dependency in your project: \`npm install --save-dev typescript@^3.7.0\` 65 | 2. Add a basic tsconfig.json file to your project: \`{"include": ["src"]}\` 66 | 3. Re-run this build. 67 | `, 68 | ); 69 | return; 70 | } 71 | 72 | reporter.info('no manual type definitions found, auto-generating...'); 73 | await execa.node( 74 | tscBin, 75 | [ 76 | '-d', 77 | '--allowJs', 78 | '--emitDeclarationOnly', 79 | '--declarationMap', 80 | 'false', 81 | '--project', 82 | tsConfigPath, 83 | '--declarationDir', 84 | path.join(out, 'dist-types/'), 85 | ...additionalArgs, 86 | ], 87 | {cwd}, 88 | ); 89 | })(); 90 | 91 | reporter.created(path.join(out, 'dist-types', 'index.d.ts'), 'types'); 92 | } 93 | -------------------------------------------------------------------------------- /packages/plugin-build-types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["src"], 4 | "exclude": ["node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/plugin-build-umd/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-build-umd 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds a UMD distribution to your package, built to be flexible & run on legacy browsers & environments. If you're looking to build for web browsers and/or UNPKG, we recommend using `@pika/plugin-build-web` instead. 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-build-umd --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-build-umd --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```json 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-standard-pkg"], 26 | ["@pika/plugin-build-umd"] 27 | ] 28 | } 29 | } 30 | ``` 31 | 32 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 33 | 34 | 35 | ## Options 36 | 37 | - `"sourcemap"` (Default: `"true"`): Adds a [source map](https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) for this build. 38 | - `"name"` (Defaults: your package name): Sets the name that your package is attached to on the `window` object. 39 | - `"entrypoint"` (Default: `"umd:main"`): Customize the package.json manifest entrypoint set by this plugin. Accepts either a string, an array of strings, or `null` to disable entrypoint. Changing this is not recommended for most usage. 40 | 41 | 42 | ## Result 43 | 44 | 1. Adds a UMD distribution to your built package: `dist-umd/index.js` 45 | 1. UMD Syntax 46 | 1. All dependencies bundled with the package. 47 | 1. Transpiled to run on all actively used and maintained browsers (excluding IE 11 and Opera Mini). 48 | 1. Adds a "umd:main" entrypoint to your built `package.json` manifest. 49 | -------------------------------------------------------------------------------- /packages/plugin-build-umd/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-build-umd", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: Adds a UMD distribution to your package, built to be flexible & run on legacy browsers & environments.", 5 | "license": "MIT", 6 | "main": "pkg/dist-node/index.js", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "@pika/plugin-ts-standard-pkg" 19 | ], 20 | [ 21 | "@pika/plugin-build-node" 22 | ] 23 | ] 24 | }, 25 | "scripts": { 26 | "build": "pika-pack build" 27 | }, 28 | "dependencies": { 29 | "@babel/core": "^7.0.0", 30 | "@babel/plugin-syntax-dynamic-import": "^7.2.0", 31 | "@babel/plugin-syntax-import-meta": "^7.2.0", 32 | "@babel/preset-env": "^7.2.3", 33 | "@pika/types": "^0.9.2", 34 | "rollup": "^2.3.0", 35 | "rollup-plugin-babel": "^4.3.0" 36 | }, 37 | "devDependencies": { 38 | "@pika/pack": "^0.5.0", 39 | "@pika/plugin-build-node": "^0.9.2", 40 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 41 | "@types/node": "^10.12.18", 42 | "typescript": "^3.0.0" 43 | }, 44 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593" 45 | } 46 | -------------------------------------------------------------------------------- /packages/plugin-build-umd/pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-build-umd 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds a UMD distribution to your package, built to be flexible & run on legacy browsers & environments. If you're looking to build for web browsers and/or UNPKG, we recommend using `@pika/plugin-build-web` instead. 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-build-umd --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-build-umd --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```json 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-standard-pkg"], 26 | ["@pika/plugin-build-umd"] 27 | ] 28 | } 29 | } 30 | ``` 31 | 32 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 33 | 34 | 35 | ## Options 36 | 37 | - `"sourcemap"` (Default: `"true"`): Adds a [source map](https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) for this build. 38 | - `"name"` (Defaults: your package name): Sets the name that your package is attached to on the `window` object. 39 | - `"entrypoint"` (Default: `"umd:main"`): Customize the package.json manifest entrypoint set by this plugin. Accepts either a string, an array of strings, or `null` to disable entrypoint. Changing this is not recommended for most usage. 40 | 41 | 42 | ## Result 43 | 44 | 1. Adds a UMD distribution to your built package: `dist-umd/index.js` 45 | 1. UMD Syntax 46 | 1. All dependencies bundled with the package. 47 | 1. Transpiled to run on all actively used and maintained browsers (excluding IE 11 and Opera Mini). 48 | 1. Adds a "umd:main" entrypoint to your built `package.json` manifest. 49 | -------------------------------------------------------------------------------- /packages/plugin-build-umd/pkg/dist-node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } 6 | 7 | var babelPluginDynamicImportSyntax = _interopDefault(require('@babel/plugin-syntax-dynamic-import')); 8 | var babelPluginImportMetaSyntax = _interopDefault(require('@babel/plugin-syntax-import-meta')); 9 | var babelPresetEnv = _interopDefault(require('@babel/preset-env')); 10 | var path = _interopDefault(require('path')); 11 | var fs = _interopDefault(require('fs')); 12 | var rollupBabel = _interopDefault(require('rollup-plugin-babel')); 13 | var types = require('@pika/types'); 14 | var rollup = require('rollup'); 15 | 16 | const DEFAULT_ENTRYPOINT = 'umd:main'; 17 | async function beforeJob({ 18 | out 19 | }) { 20 | const srcDirectory = path.join(out, 'dist-src/'); 21 | 22 | if (!fs.existsSync(srcDirectory)) { 23 | throw new types.MessageError('"dist-src/" does not exist, or was not yet created in the pipeline.'); 24 | } 25 | 26 | const srcEntrypoint = path.join(out, 'dist-src/index.js'); 27 | 28 | if (!fs.existsSync(srcEntrypoint)) { 29 | throw new types.MessageError('"dist-src/index.js" is the expected standard entrypoint, but it does not exist.'); 30 | } 31 | } 32 | function manifest(manifest, { 33 | options 34 | }) { 35 | if (options.entrypoint !== null) { 36 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 37 | 38 | if (typeof keys === 'string') { 39 | keys = [keys]; 40 | } 41 | 42 | for (const key of keys) { 43 | manifest[key] = manifest[key] || 'dist-umd/index.js'; 44 | } 45 | } 46 | } 47 | async function build({ 48 | out, 49 | reporter, 50 | options 51 | }) { 52 | const umdExportName = options.name || manifest.name; 53 | const writeToUmd = path.join(out, 'dist-umd', 'index.js'); 54 | const result = await rollup.rollup({ 55 | input: path.join(out, 'dist-src/index.js'), 56 | plugins: [rollupBabel({ 57 | babelrc: false, 58 | compact: false, 59 | presets: [[babelPresetEnv, { 60 | modules: false, 61 | spec: true, 62 | targets: { 63 | // Recommended in: https://jamie.build/last-2-versions 64 | browsers: ['>0.25%', 'not op_mini all'] 65 | } 66 | }]], 67 | plugins: [babelPluginDynamicImportSyntax, babelPluginImportMetaSyntax] 68 | })], 69 | onwarn: (warning, defaultOnWarnHandler) => { 70 | // // Unresolved external imports are expected 71 | if (warning.code === 'UNRESOLVED_IMPORT' && !(warning.source.startsWith('./') || warning.source.startsWith('../'))) { 72 | return; 73 | } 74 | 75 | defaultOnWarnHandler(warning); 76 | } 77 | }); 78 | await result.write({ 79 | file: writeToUmd, 80 | format: 'umd', 81 | exports: 'named', 82 | name: umdExportName, 83 | sourcemap: options.sourcemap === undefined ? true : options.sourcemap 84 | }); 85 | reporter.created(writeToUmd, 'umd:main'); 86 | } 87 | 88 | exports.beforeJob = beforeJob; 89 | exports.build = build; 90 | exports.manifest = manifest; 91 | //# sourceMappingURL=index.js.map 92 | -------------------------------------------------------------------------------- /packages/plugin-build-umd/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | import babelPluginDynamicImportSyntax from '@babel/plugin-syntax-dynamic-import'; 2 | import babelPluginImportMetaSyntax from '@babel/plugin-syntax-import-meta'; 3 | import babelPresetEnv from '@babel/preset-env'; 4 | import path from 'path'; 5 | import fs from 'fs'; 6 | import rollupBabel from 'rollup-plugin-babel'; 7 | import { MessageError } from '@pika/types'; 8 | import { rollup } from 'rollup'; 9 | const DEFAULT_ENTRYPOINT = 'umd:main'; 10 | export async function beforeJob({ out }) { 11 | const srcDirectory = path.join(out, 'dist-src/'); 12 | if (!fs.existsSync(srcDirectory)) { 13 | throw new MessageError('"dist-src/" does not exist, or was not yet created in the pipeline.'); 14 | } 15 | const srcEntrypoint = path.join(out, 'dist-src/index.js'); 16 | if (!fs.existsSync(srcEntrypoint)) { 17 | throw new MessageError('"dist-src/index.js" is the expected standard entrypoint, but it does not exist.'); 18 | } 19 | } 20 | export function manifest(manifest, { options }) { 21 | if (options.entrypoint !== null) { 22 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 23 | if (typeof keys === 'string') { 24 | keys = [keys]; 25 | } 26 | for (const key of keys) { 27 | manifest[key] = manifest[key] || 'dist-umd/index.js'; 28 | } 29 | } 30 | } 31 | export async function build({ out, reporter, options }) { 32 | const umdExportName = options.name || manifest.name; 33 | const writeToUmd = path.join(out, 'dist-umd', 'index.js'); 34 | const result = await rollup({ 35 | input: path.join(out, 'dist-src/index.js'), 36 | plugins: [ 37 | rollupBabel({ 38 | babelrc: false, 39 | compact: false, 40 | presets: [ 41 | [ 42 | babelPresetEnv, 43 | { 44 | modules: false, 45 | spec: true, 46 | targets: { 47 | // Recommended in: https://jamie.build/last-2-versions 48 | browsers: ['>0.25%', 'not op_mini all'], 49 | }, 50 | }, 51 | ], 52 | ], 53 | plugins: [babelPluginDynamicImportSyntax, babelPluginImportMetaSyntax], 54 | }), 55 | ], 56 | onwarn: ((warning, defaultOnWarnHandler) => { 57 | // // Unresolved external imports are expected 58 | if (warning.code === 'UNRESOLVED_IMPORT' && 59 | !(warning.source.startsWith('./') || warning.source.startsWith('../'))) { 60 | return; 61 | } 62 | defaultOnWarnHandler(warning); 63 | }), 64 | }); 65 | await result.write({ 66 | file: writeToUmd, 67 | format: 'umd', 68 | exports: 'named', 69 | name: umdExportName, 70 | sourcemap: options.sourcemap === undefined ? true : options.sourcemap, 71 | }); 72 | reporter.created(writeToUmd, 'umd:main'); 73 | } 74 | -------------------------------------------------------------------------------- /packages/plugin-build-umd/pkg/dist-types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { BuilderOptions } from '@pika/types'; 2 | export declare function beforeJob({ out }: BuilderOptions): Promise; 3 | export declare function manifest(manifest: any, { options }: BuilderOptions): void; 4 | export declare function build({ out, reporter, options }: BuilderOptions): Promise; 5 | -------------------------------------------------------------------------------- /packages/plugin-build-umd/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-build-umd", 3 | "description": "A @pika/pack plugin: Adds a UMD distribution to your package, built to be flexible & run on legacy browsers & environments.", 4 | "version": "0.9.2", 5 | "license": "MIT", 6 | "files": [ 7 | "dist-*/", 8 | "bin/" 9 | ], 10 | "pika": true, 11 | "sideEffects": false, 12 | "homepage": "https://www.pikapkg.com", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/pikapkg/builders.git" 16 | }, 17 | "dependencies": { 18 | "@babel/core": "^7.0.0", 19 | "@babel/plugin-syntax-dynamic-import": "^7.2.0", 20 | "@babel/plugin-syntax-import-meta": "^7.2.0", 21 | "@babel/preset-env": "^7.2.3", 22 | "@pika/types": "^0.9.2", 23 | "rollup": "^2.3.0", 24 | "rollup-plugin-babel": "^4.3.0" 25 | }, 26 | "devDependencies": { 27 | "@pika/pack": "^0.5.0", 28 | "@pika/plugin-build-node": "^0.9.2", 29 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 30 | "@types/node": "^10.12.18", 31 | "typescript": "^3.0.0" 32 | }, 33 | "publishConfig": { 34 | "access": "public" 35 | }, 36 | "source": "dist-src/index.js", 37 | "types": "dist-types/index.d.ts", 38 | "main": "dist-node/index.js" 39 | } 40 | -------------------------------------------------------------------------------- /packages/plugin-build-umd/src/index.ts: -------------------------------------------------------------------------------- 1 | import babelPluginDynamicImportSyntax from '@babel/plugin-syntax-dynamic-import'; 2 | import babelPluginImportMetaSyntax from '@babel/plugin-syntax-import-meta'; 3 | import babelPresetEnv from '@babel/preset-env'; 4 | import path from 'path'; 5 | import fs from 'fs'; 6 | import rollupBabel from 'rollup-plugin-babel'; 7 | import {BuilderOptions, MessageError} from '@pika/types'; 8 | import {rollup} from 'rollup'; 9 | const DEFAULT_ENTRYPOINT = 'umd:main'; 10 | 11 | export async function beforeJob({out}: BuilderOptions) { 12 | const srcDirectory = path.join(out, 'dist-src/'); 13 | if (!fs.existsSync(srcDirectory)) { 14 | throw new MessageError('"dist-src/" does not exist, or was not yet created in the pipeline.'); 15 | } 16 | const srcEntrypoint = path.join(out, 'dist-src/index.js'); 17 | if (!fs.existsSync(srcEntrypoint)) { 18 | throw new MessageError('"dist-src/index.js" is the expected standard entrypoint, but it does not exist.'); 19 | } 20 | } 21 | 22 | export function manifest(manifest, {options}: BuilderOptions) { 23 | if (options.entrypoint !== null) { 24 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 25 | if (typeof keys === 'string') { 26 | keys = [keys]; 27 | } 28 | for (const key of keys) { 29 | manifest[key] = manifest[key] || 'dist-umd/index.js'; 30 | } 31 | } 32 | } 33 | 34 | export async function build({out, reporter, options}: BuilderOptions): Promise { 35 | const umdExportName = options.name || manifest.name; 36 | const writeToUmd = path.join(out, 'dist-umd', 'index.js'); 37 | 38 | const result = await rollup({ 39 | input: path.join(out, 'dist-src/index.js'), 40 | plugins: [ 41 | rollupBabel({ 42 | babelrc: false, 43 | compact: false, 44 | presets: [ 45 | [ 46 | babelPresetEnv, 47 | { 48 | modules: false, 49 | spec: true, 50 | targets: { 51 | // Recommended in: https://jamie.build/last-2-versions 52 | browsers: ['>0.25%', 'not op_mini all'], 53 | }, 54 | }, 55 | ], 56 | ], 57 | plugins: [babelPluginDynamicImportSyntax, babelPluginImportMetaSyntax], 58 | }), 59 | ], 60 | onwarn: ((warning, defaultOnWarnHandler) => { 61 | // // Unresolved external imports are expected 62 | if ( 63 | warning.code === 'UNRESOLVED_IMPORT' && 64 | !(warning.source.startsWith('./') || warning.source.startsWith('../')) 65 | ) { 66 | return; 67 | } 68 | defaultOnWarnHandler(warning); 69 | }) as any, 70 | }); 71 | 72 | await result.write({ 73 | file: writeToUmd, 74 | format: 'umd', 75 | exports: 'named', 76 | name: umdExportName, 77 | sourcemap: options.sourcemap === undefined ? true : options.sourcemap, 78 | }); 79 | reporter.created(writeToUmd, 'umd:main'); 80 | } 81 | -------------------------------------------------------------------------------- /packages/plugin-build-umd/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["src"], 4 | "exclude": ["node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/plugin-build-web/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-build-web 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds an ESM distribution to your package optimized for web bundlers and tooling. For a standalone build meant to run directly in the browser, check out [plugin-bundle-web](/packages/plugin-bundle-web). 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-build-web --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-build-web --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```json 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-standard-pkg"], 26 | ["@pika/plugin-build-web"] 27 | ] 28 | } 29 | } 30 | ``` 31 | 32 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 33 | 34 | ## Options 35 | 36 | - `"sourcemap"` (Default: `"true"`): Adds a [source map](https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) for this build. 37 | - `"entrypoint"` (Default: `"module"`): Customize the package.json manifest entrypoint set by this plugin. Accepts either a string, an array of strings, or `null` to disable entrypoint. Changing this is not recommended for most usage. 38 | 39 | 40 | ## Result 41 | 42 | 1. Adds a web distribution to your built package: `dist-web/index.js` Targets Modern (ES2020) syntax optimized for bundlers & web tooling. 43 | 1. Adds a "module" entrypoint to your built `package.json` manifest. 44 | 45 | Packages that use this plugin will work on the Pika CDN. To support running directly from UNPKG, check out [plugin-bundle-web](/packages/plugin-bundle-web). -------------------------------------------------------------------------------- /packages/plugin-build-web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-build-web", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: Adds an ESM distribution to your package, built & optimized to run in most web browsers (and bundlers).", 5 | "license": "MIT", 6 | "main": "pkg/dist-node/index.js", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "@pika/plugin-ts-standard-pkg" 19 | ], 20 | [ 21 | "@pika/plugin-build-node" 22 | ] 23 | ] 24 | }, 25 | "scripts": { 26 | "build": "pika-pack build" 27 | }, 28 | "dependencies": { 29 | "@pika/types": "^0.9.2", 30 | "@types/node": "^10.12.18", 31 | "rollup": "^2.3.0" 32 | }, 33 | "devDependencies": { 34 | "@pika/pack": "^0.5.0", 35 | "@pika/plugin-build-node": "^0.9.2", 36 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 37 | "@types/node": "^10.12.18", 38 | "typescript": "^3.0.0" 39 | }, 40 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593" 41 | } 42 | -------------------------------------------------------------------------------- /packages/plugin-build-web/pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-build-web 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds an ESM distribution to your package optimized for web bundlers and tooling. For a standalone build meant to run directly in the browser, check out [plugin-bundle-web](/packages/plugin-bundle-web). 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-build-web --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-build-web --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```json 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-standard-pkg"], 26 | ["@pika/plugin-build-web"] 27 | ] 28 | } 29 | } 30 | ``` 31 | 32 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 33 | 34 | ## Options 35 | 36 | - `"sourcemap"` (Default: `"true"`): Adds a [source map](https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) for this build. 37 | - `"entrypoint"` (Default: `"module"`): Customize the package.json manifest entrypoint set by this plugin. Accepts either a string, an array of strings, or `null` to disable entrypoint. Changing this is not recommended for most usage. 38 | 39 | 40 | ## Result 41 | 42 | 1. Adds a web distribution to your built package: `dist-web/index.js` Targets Modern (ES2020) syntax optimized for bundlers & web tooling. 43 | 1. Adds a "module" entrypoint to your built `package.json` manifest. 44 | 45 | Packages that use this plugin will work on the Pika CDN. To support running directly from UNPKG, check out [plugin-bundle-web](/packages/plugin-bundle-web). -------------------------------------------------------------------------------- /packages/plugin-build-web/pkg/dist-node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } 6 | 7 | var path = _interopDefault(require('path')); 8 | var fs = _interopDefault(require('fs')); 9 | var types = require('@pika/types'); 10 | var rollup = require('rollup'); 11 | 12 | const DEFAULT_ENTRYPOINT = 'module'; 13 | async function beforeJob({ 14 | out 15 | }) { 16 | const srcDirectory = path.join(out, 'dist-src/'); 17 | 18 | if (!fs.existsSync(srcDirectory)) { 19 | throw new types.MessageError('"dist-src/" does not exist, or was not yet created in the pipeline.'); 20 | } 21 | 22 | const srcEntrypoint = path.join(out, 'dist-src/index.js'); 23 | 24 | if (!fs.existsSync(srcEntrypoint)) { 25 | throw new types.MessageError('"dist-src/index.js" is the expected standard entrypoint, but it does not exist.'); 26 | } 27 | } 28 | function manifest(manifest, { 29 | options 30 | }) { 31 | if (options.entrypoint !== null) { 32 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 33 | 34 | if (typeof keys === 'string') { 35 | keys = [keys]; 36 | } 37 | 38 | for (const key of keys) { 39 | manifest[key] = manifest[key] || 'dist-web/index.js'; 40 | } 41 | } 42 | } 43 | async function build({ 44 | out, 45 | options, 46 | reporter 47 | }) { 48 | const writeToWeb = path.join(out, 'dist-web', 'index.js'); 49 | const result = await rollup.rollup({ 50 | input: path.join(out, 'dist-src/index.js'), 51 | plugins: [], 52 | onwarn: (warning, defaultOnWarnHandler) => { 53 | // // Unresolved external imports are expected 54 | if (warning.code === 'UNRESOLVED_IMPORT' && !(warning.source.startsWith('./') || warning.source.startsWith('../'))) { 55 | return; 56 | } 57 | 58 | defaultOnWarnHandler(warning); 59 | } 60 | }); 61 | await result.write({ 62 | file: writeToWeb, 63 | format: 'esm', 64 | exports: 'named', 65 | sourcemap: options.sourcemap === undefined ? true : options.sourcemap 66 | }); 67 | reporter.created(writeToWeb, 'module'); 68 | } 69 | 70 | exports.beforeJob = beforeJob; 71 | exports.build = build; 72 | exports.manifest = manifest; 73 | //# sourceMappingURL=index.js.map 74 | -------------------------------------------------------------------------------- /packages/plugin-build-web/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import { MessageError } from '@pika/types'; 4 | import { rollup } from 'rollup'; 5 | const DEFAULT_ENTRYPOINT = 'module'; 6 | export async function beforeJob({ out }) { 7 | const srcDirectory = path.join(out, 'dist-src/'); 8 | if (!fs.existsSync(srcDirectory)) { 9 | throw new MessageError('"dist-src/" does not exist, or was not yet created in the pipeline.'); 10 | } 11 | const srcEntrypoint = path.join(out, 'dist-src/index.js'); 12 | if (!fs.existsSync(srcEntrypoint)) { 13 | throw new MessageError('"dist-src/index.js" is the expected standard entrypoint, but it does not exist.'); 14 | } 15 | } 16 | export function manifest(manifest, { options }) { 17 | if (options.entrypoint !== null) { 18 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 19 | if (typeof keys === 'string') { 20 | keys = [keys]; 21 | } 22 | for (const key of keys) { 23 | manifest[key] = manifest[key] || 'dist-web/index.js'; 24 | } 25 | } 26 | } 27 | export async function build({ out, options, reporter }) { 28 | const writeToWeb = path.join(out, 'dist-web', 'index.js'); 29 | const result = await rollup({ 30 | input: path.join(out, 'dist-src/index.js'), 31 | plugins: [], 32 | onwarn: ((warning, defaultOnWarnHandler) => { 33 | // // Unresolved external imports are expected 34 | if (warning.code === 'UNRESOLVED_IMPORT' && 35 | !(warning.source.startsWith('./') || warning.source.startsWith('../'))) { 36 | return; 37 | } 38 | defaultOnWarnHandler(warning); 39 | }), 40 | }); 41 | await result.write({ 42 | file: writeToWeb, 43 | format: 'esm', 44 | exports: 'named', 45 | sourcemap: options.sourcemap === undefined ? true : options.sourcemap, 46 | }); 47 | reporter.created(writeToWeb, 'module'); 48 | } 49 | -------------------------------------------------------------------------------- /packages/plugin-build-web/pkg/dist-types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { BuilderOptions } from '@pika/types'; 2 | export declare function beforeJob({ out }: BuilderOptions): Promise; 3 | export declare function manifest(manifest: any, { options }: BuilderOptions): void; 4 | export declare function build({ out, options, reporter }: BuilderOptions): Promise; 5 | -------------------------------------------------------------------------------- /packages/plugin-build-web/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-build-web", 3 | "description": "A @pika/pack plugin: Adds an ESM distribution to your package, built & optimized to run in most web browsers (and bundlers).", 4 | "version": "0.9.2", 5 | "license": "MIT", 6 | "files": [ 7 | "dist-*/", 8 | "bin/" 9 | ], 10 | "pika": true, 11 | "sideEffects": false, 12 | "homepage": "https://www.pikapkg.com", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/pikapkg/builders.git" 16 | }, 17 | "dependencies": { 18 | "@pika/types": "^0.9.2", 19 | "@types/node": "^10.12.18", 20 | "rollup": "^2.3.0" 21 | }, 22 | "devDependencies": { 23 | "@pika/pack": "^0.5.0", 24 | "@pika/plugin-build-node": "^0.9.2", 25 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 26 | "typescript": "^3.0.0" 27 | }, 28 | "publishConfig": { 29 | "access": "public" 30 | }, 31 | "source": "dist-src/index.js", 32 | "types": "dist-types/index.d.ts", 33 | "main": "dist-node/index.js" 34 | } 35 | -------------------------------------------------------------------------------- /packages/plugin-build-web/src/index.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import {BuilderOptions, MessageError} from '@pika/types'; 4 | import {rollup} from 'rollup'; 5 | const DEFAULT_ENTRYPOINT = 'module'; 6 | export async function beforeJob({out}: BuilderOptions) { 7 | const srcDirectory = path.join(out, 'dist-src/'); 8 | if (!fs.existsSync(srcDirectory)) { 9 | throw new MessageError('"dist-src/" does not exist, or was not yet created in the pipeline.'); 10 | } 11 | const srcEntrypoint = path.join(out, 'dist-src/index.js'); 12 | if (!fs.existsSync(srcEntrypoint)) { 13 | throw new MessageError('"dist-src/index.js" is the expected standard entrypoint, but it does not exist.'); 14 | } 15 | } 16 | 17 | export function manifest(manifest, {options}: BuilderOptions) { 18 | if (options.entrypoint !== null) { 19 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 20 | if (typeof keys === 'string') { 21 | keys = [keys]; 22 | } 23 | for (const key of keys) { 24 | manifest[key] = manifest[key] || 'dist-web/index.js'; 25 | } 26 | } 27 | } 28 | 29 | export async function build({out, options, reporter}: BuilderOptions): Promise { 30 | const writeToWeb = path.join(out, 'dist-web', 'index.js'); 31 | 32 | const result = await rollup({ 33 | input: path.join(out, 'dist-src/index.js'), 34 | plugins: [], 35 | onwarn: ((warning, defaultOnWarnHandler) => { 36 | // // Unresolved external imports are expected 37 | if ( 38 | warning.code === 'UNRESOLVED_IMPORT' && 39 | !(warning.source.startsWith('./') || warning.source.startsWith('../')) 40 | ) { 41 | return; 42 | } 43 | defaultOnWarnHandler(warning); 44 | }) as any, 45 | }); 46 | 47 | await result.write({ 48 | file: writeToWeb, 49 | format: 'esm', 50 | exports: 'named', 51 | sourcemap: options.sourcemap === undefined ? true : options.sourcemap, 52 | }); 53 | reporter.created(writeToWeb, 'module'); 54 | } 55 | -------------------------------------------------------------------------------- /packages/plugin-build-web/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["src"], 4 | "exclude": ["node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/plugin-bundle-node/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-bundle-node 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds a bundled Node.js distribution to your package, built & optimized to run on [Node.js](https://nodejs.org/) with all dependencies included. Useful for reducing the install time for CLIs. 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-bundle-node --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-bundle-node --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```json 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-standard-pkg"], 26 | ["@pika/plugin-build-node"], 27 | ["@pika/plugin-bundle-node"] 28 | ] 29 | } 30 | } 31 | ``` 32 | 33 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 34 | 35 | ## Options 36 | 37 | - `"sourcemap"` (Default: `"true"`): Adds a [source map](https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) for this build. 38 | - `"minNodeVersion"` (Default: `"10"`): This plugin will bundle your package for the current minimum [Node.js LTS](https://github.com/nodejs/Release) major version. This option allows you to target later versions of Node.js only. 39 | 40 | 41 | ## Result 42 | 43 | 1. Adds a bundled Node.js distribution to your built package: `dist-node/index.bundled.js` 44 | 1. Common.js (CJS) Module Syntax. 45 | 1. All dependencies included in this file. 46 | 47 | Note that this does not add or modify the "main" entrypoint to your package.json. See `@pika/plugin-simple-bin` for an example of how to automatically point to this bundled build. 48 | -------------------------------------------------------------------------------- /packages/plugin-bundle-node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-bundle-node", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: Adds a bundled Node.js distribution to your package.", 5 | "license": "MIT", 6 | "main": "pkg/dist-node/index.js", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "@pika/plugin-ts-standard-pkg" 19 | ], 20 | [ 21 | "@pika/plugin-build-node" 22 | ] 23 | ] 24 | }, 25 | "scripts": { 26 | "build": "pika-pack build" 27 | }, 28 | "dependencies": { 29 | "@babel/core": "^7.0.0", 30 | "@babel/plugin-syntax-dynamic-import": "^7.2.0", 31 | "@babel/plugin-syntax-import-meta": "^7.2.0", 32 | "@babel/preset-env": "^7.2.3", 33 | "@pika/types": "^0.9.2", 34 | "@rollup/plugin-commonjs": "^11.0.0", 35 | "@rollup/plugin-json": "^4.0.0", 36 | "@rollup/plugin-node-resolve": "^7.0.0", 37 | "babel-plugin-dynamic-import-node-babel-7": "^2.0.7", 38 | "builtin-modules": "^3.0.0", 39 | "rollup": "^2.3.0", 40 | "rollup-plugin-babel": "^4.3.0" 41 | }, 42 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593", 43 | "devDependencies": { 44 | "@pika/pack": "^0.5.0", 45 | "@pika/plugin-build-node": "^0.9.2", 46 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 47 | "@types/node": "^10.12.18", 48 | "typescript": "^3.0.0" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /packages/plugin-bundle-node/pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-bundle-node 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds a bundled Node.js distribution to your package, built & optimized to run on [Node.js](https://nodejs.org/) with all dependencies included. Useful for reducing the install time for CLIs. 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-bundle-node --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-bundle-node --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```json 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-standard-pkg"], 26 | ["@pika/plugin-build-node"], 27 | ["@pika/plugin-bundle-node"] 28 | ] 29 | } 30 | } 31 | ``` 32 | 33 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 34 | 35 | ## Options 36 | 37 | - `"sourcemap"` (Default: `"true"`): Adds a [source map](https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) for this build. 38 | - `"minNodeVersion"` (Default: `"8"`): This plugin will bundle your package for the current minimum [Node.js LTS](https://github.com/nodejs/Release) major version. This option allows you to target later versions of Node.js only. 39 | 40 | 41 | ## Result 42 | 43 | 1. Adds a bundled Node.js distribution to your built package: `dist-node/index.bundled.js` 44 | 1. Common.js (CJS) Module Syntax. 45 | 1. All dependencies included in this file. 46 | 47 | Note that this does not add or modify the "main" entrypoint to your package.json. See `@pika/plugin-simple-bin` for an example of how to automatically point to this bundled build. 48 | -------------------------------------------------------------------------------- /packages/plugin-bundle-node/pkg/dist-node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } 6 | 7 | var babelPluginDynamicImportSyntax = _interopDefault(require('@babel/plugin-syntax-dynamic-import')); 8 | var babelPluginImportMetaSyntax = _interopDefault(require('@babel/plugin-syntax-import-meta')); 9 | var babelPresetEnv = _interopDefault(require('@babel/preset-env')); 10 | var types = require('@pika/types'); 11 | var babelPluginDynamicImport = _interopDefault(require('babel-plugin-dynamic-import-node-babel-7')); 12 | var builtinModules = _interopDefault(require('builtin-modules')); 13 | var fs = require('fs'); 14 | var path = require('path'); 15 | var rollupBabel = _interopDefault(require('rollup-plugin-babel')); 16 | var rollupCommonJs = _interopDefault(require('@rollup/plugin-commonjs')); 17 | var rollupJson = _interopDefault(require('@rollup/plugin-json')); 18 | var rollupNodeResolve = _interopDefault(require('@rollup/plugin-node-resolve')); 19 | var rollup = require('rollup'); 20 | 21 | const DEFAULT_MIN_NODE_VERSION = '8'; 22 | async function beforeJob({ 23 | out 24 | }) { 25 | const srcDirectory = path.join(out, 'dist-src/'); 26 | 27 | if (!fs.existsSync(srcDirectory)) { 28 | throw new types.MessageError('"dist-src/" does not exist, or was not yet created in the pipeline.'); 29 | } 30 | 31 | const srcEntrypoint = path.join(out, 'dist-src/index.js'); 32 | 33 | if (!fs.existsSync(srcEntrypoint)) { 34 | throw new types.MessageError('"dist-src/index.js" is the expected standard entrypoint, but it does not exist.'); 35 | } 36 | } 37 | async function build({ 38 | out, 39 | reporter, 40 | options 41 | }) { 42 | const writeToNode = path.join(out, 'dist-node'); 43 | const writeToNodeBundled = path.join(writeToNode, 'index.bundled.js'); 44 | const result = await rollup.rollup({ 45 | input: path.join(out, 'dist-src/index.js'), 46 | external: builtinModules, 47 | plugins: [rollupBabel({ 48 | babelrc: false, 49 | compact: false, 50 | presets: [[babelPresetEnv, { 51 | modules: false, 52 | targets: { 53 | node: options.minNodeVersion || DEFAULT_MIN_NODE_VERSION 54 | }, 55 | spec: true 56 | }]], 57 | plugins: [babelPluginDynamicImport, babelPluginDynamicImportSyntax, babelPluginImportMetaSyntax] 58 | }), rollupNodeResolve({ 59 | mainFields: ['main'], 60 | preferBuiltins: false 61 | }), rollupCommonJs({ 62 | sourceMap: false 63 | }), rollupJson({ 64 | compact: true 65 | })] 66 | }); 67 | await result.write({ 68 | dir: writeToNode, 69 | entryFileNames: '[name].bundled.js', 70 | chunkFileNames: '[name]-[hash].bundled.js', 71 | format: 'cjs', 72 | exports: 'named', 73 | sourcemap: options.sourcemap === undefined ? true : options.sourcemap 74 | }); 75 | reporter.created(writeToNodeBundled); 76 | } 77 | 78 | exports.beforeJob = beforeJob; 79 | exports.build = build; 80 | //# sourceMappingURL=index.js.map 81 | -------------------------------------------------------------------------------- /packages/plugin-bundle-node/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | import babelPluginDynamicImportSyntax from '@babel/plugin-syntax-dynamic-import'; 2 | import babelPluginImportMetaSyntax from '@babel/plugin-syntax-import-meta'; 3 | import babelPresetEnv from '@babel/preset-env'; 4 | import { MessageError } from '@pika/types'; 5 | import babelPluginDynamicImport from 'babel-plugin-dynamic-import-node-babel-7'; 6 | import builtinModules from 'builtin-modules'; 7 | import * as fs from 'fs'; 8 | import * as path from 'path'; 9 | import rollupBabel from 'rollup-plugin-babel'; 10 | import rollupCommonJs from '@rollup/plugin-commonjs'; 11 | import rollupJson from '@rollup/plugin-json'; 12 | import rollupNodeResolve from '@rollup/plugin-node-resolve'; 13 | import { rollup } from 'rollup'; 14 | const DEFAULT_MIN_NODE_VERSION = '8'; 15 | export async function beforeJob({ out }) { 16 | const srcDirectory = path.join(out, 'dist-src/'); 17 | if (!fs.existsSync(srcDirectory)) { 18 | throw new MessageError('"dist-src/" does not exist, or was not yet created in the pipeline.'); 19 | } 20 | const srcEntrypoint = path.join(out, 'dist-src/index.js'); 21 | if (!fs.existsSync(srcEntrypoint)) { 22 | throw new MessageError('"dist-src/index.js" is the expected standard entrypoint, but it does not exist.'); 23 | } 24 | } 25 | export async function build({ out, reporter, options }) { 26 | const writeToNode = path.join(out, 'dist-node'); 27 | const writeToNodeBundled = path.join(writeToNode, 'index.bundled.js'); 28 | const result = await rollup({ 29 | input: path.join(out, 'dist-src/index.js'), 30 | external: builtinModules, 31 | plugins: [ 32 | rollupBabel({ 33 | babelrc: false, 34 | compact: false, 35 | presets: [ 36 | [ 37 | babelPresetEnv, 38 | { 39 | modules: false, 40 | targets: { node: options.minNodeVersion || DEFAULT_MIN_NODE_VERSION }, 41 | spec: true, 42 | }, 43 | ], 44 | ], 45 | plugins: [babelPluginDynamicImport, babelPluginDynamicImportSyntax, babelPluginImportMetaSyntax], 46 | }), 47 | rollupNodeResolve({ 48 | mainFields: ['main'], 49 | preferBuiltins: false, 50 | }), 51 | rollupCommonJs({ 52 | sourceMap: false, 53 | }), 54 | rollupJson({ 55 | compact: true, 56 | }), 57 | ], 58 | }); 59 | await result.write({ 60 | dir: writeToNode, 61 | entryFileNames: '[name].bundled.js', 62 | chunkFileNames: '[name]-[hash].bundled.js', 63 | format: 'cjs', 64 | exports: 'named', 65 | sourcemap: options.sourcemap === undefined ? true : options.sourcemap, 66 | }); 67 | reporter.created(writeToNodeBundled); 68 | } 69 | -------------------------------------------------------------------------------- /packages/plugin-bundle-node/pkg/dist-types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { BuilderOptions } from '@pika/types'; 2 | export declare function beforeJob({ out }: BuilderOptions): Promise; 3 | export declare function build({ out, reporter, options }: BuilderOptions): Promise; 4 | -------------------------------------------------------------------------------- /packages/plugin-bundle-node/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-bundle-node", 3 | "description": "A @pika/pack plugin: Adds a bundled Node.js distribution to your package.", 4 | "version": "0.9.2", 5 | "license": "MIT", 6 | "files": [ 7 | "dist-*/", 8 | "bin/" 9 | ], 10 | "pika": true, 11 | "sideEffects": false, 12 | "homepage": "https://www.pikapkg.com", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/pikapkg/builders.git" 16 | }, 17 | "dependencies": { 18 | "@babel/core": "^7.0.0", 19 | "@babel/plugin-syntax-dynamic-import": "^7.2.0", 20 | "@babel/plugin-syntax-import-meta": "^7.2.0", 21 | "@babel/preset-env": "^7.2.3", 22 | "@pika/types": "^0.9.2", 23 | "@rollup/plugin-commonjs": "^11.0.0", 24 | "@rollup/plugin-json": "^4.0.0", 25 | "@rollup/plugin-node-resolve": "^7.0.0", 26 | "babel-plugin-dynamic-import-node-babel-7": "^2.0.7", 27 | "builtin-modules": "^3.0.0", 28 | "rollup": "^2.3.0", 29 | "rollup-plugin-babel": "^4.3.0" 30 | }, 31 | "devDependencies": { 32 | "@pika/pack": "^0.5.0", 33 | "@pika/plugin-build-node": "^0.9.2", 34 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 35 | "@types/node": "^10.12.18", 36 | "typescript": "^3.0.0" 37 | }, 38 | "publishConfig": { 39 | "access": "public" 40 | }, 41 | "source": "dist-src/index.js", 42 | "types": "dist-types/index.d.ts", 43 | "main": "dist-node/index.js" 44 | } 45 | -------------------------------------------------------------------------------- /packages/plugin-bundle-node/src/index.ts: -------------------------------------------------------------------------------- 1 | import babelPluginDynamicImportSyntax from '@babel/plugin-syntax-dynamic-import'; 2 | import babelPluginImportMetaSyntax from '@babel/plugin-syntax-import-meta'; 3 | import babelPresetEnv from '@babel/preset-env'; 4 | import {BuilderOptions, MessageError} from '@pika/types'; 5 | import babelPluginDynamicImport from 'babel-plugin-dynamic-import-node-babel-7'; 6 | import builtinModules from 'builtin-modules'; 7 | import * as fs from 'fs'; 8 | import * as path from 'path'; 9 | import rollupBabel from 'rollup-plugin-babel'; 10 | import rollupCommonJs from '@rollup/plugin-commonjs'; 11 | import rollupJson from '@rollup/plugin-json'; 12 | import rollupNodeResolve from '@rollup/plugin-node-resolve'; 13 | import {rollup} from 'rollup'; 14 | 15 | const DEFAULT_MIN_NODE_VERSION = '10'; 16 | 17 | export async function beforeJob({out}: BuilderOptions) { 18 | const srcDirectory = path.join(out, 'dist-src/'); 19 | if (!fs.existsSync(srcDirectory)) { 20 | throw new MessageError('"dist-src/" does not exist, or was not yet created in the pipeline.'); 21 | } 22 | const srcEntrypoint = path.join(out, 'dist-src/index.js'); 23 | if (!fs.existsSync(srcEntrypoint)) { 24 | throw new MessageError('"dist-src/index.js" is the expected standard entrypoint, but it does not exist.'); 25 | } 26 | } 27 | 28 | export async function build({out, reporter, options}: BuilderOptions): Promise { 29 | const writeToNode = path.join(out, 'dist-node'); 30 | const writeToNodeBundled = path.join(writeToNode, 'index.bundled.js'); 31 | const result = await rollup({ 32 | input: path.join(out, 'dist-src/index.js'), 33 | external: builtinModules as string[], 34 | plugins: [ 35 | rollupBabel({ 36 | babelrc: false, 37 | compact: false, 38 | presets: [ 39 | [ 40 | babelPresetEnv, 41 | { 42 | modules: false, 43 | targets: {node: options.minNodeVersion || DEFAULT_MIN_NODE_VERSION}, 44 | spec: true, 45 | }, 46 | ], 47 | ], 48 | plugins: [babelPluginDynamicImport, babelPluginDynamicImportSyntax, babelPluginImportMetaSyntax], 49 | }), 50 | rollupNodeResolve({ 51 | mainFields: ['main'], 52 | preferBuiltins: false, 53 | }), 54 | rollupCommonJs({ 55 | sourceMap: false, 56 | }), 57 | rollupJson({ 58 | compact: true, 59 | }), 60 | ], 61 | }); 62 | 63 | await result.write({ 64 | dir: writeToNode, 65 | entryFileNames: '[name].bundled.js', 66 | chunkFileNames: '[name]-[hash].bundled.js', 67 | format: 'cjs', 68 | exports: 'named', 69 | sourcemap: options.sourcemap === undefined ? true : options.sourcemap, 70 | }); 71 | reporter.created(writeToNodeBundled); 72 | } 73 | -------------------------------------------------------------------------------- /packages/plugin-bundle-node/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["src"], 4 | "exclude": ["node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/plugin-bundle-types/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-bundle-types 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Bundle & tree-shake all TypeScript definitions into a single file. 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-bundle-types --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-bundle-types --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```json 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-ts-standard-pkg"], 26 | ["@pika/plugin-build-node"], 27 | ["@pika/plugin-bundle-types"] 28 | ] 29 | } 30 | } 31 | ``` 32 | 33 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 34 | 35 | ## Options 36 | 37 | - `"tsconfig"`: The relative path to the `tsconfig.json` config file to use. Defaults to the top-level project TypeScript config file, if one exists. 38 | - `"entrypoint"` (Default: `"types"`): Customize the package.json manifest entrypoint set by this plugin. Accepts either a string, an array of strings, or `null` to disable entrypoint. Changing this is not recommended for most usage. 39 | 40 | ## Result 41 | 42 | TODO -------------------------------------------------------------------------------- /packages/plugin-bundle-types/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-bundle-types", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: Bundle & tree-shake all TypeScript definitions into a single file.", 5 | "license": "MIT", 6 | "main": "pkg/dist-node/index.js", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "@pika/plugin-ts-standard-pkg" 19 | ], 20 | [ 21 | "@pika/plugin-build-node" 22 | ] 23 | ] 24 | }, 25 | "scripts": { 26 | "build": "pika-pack build" 27 | }, 28 | "dependencies": { 29 | "@pika/types": "^0.9.2", 30 | "rimraf": "^3.0.0", 31 | "rollup": "^2.3.0", 32 | "rollup-plugin-dts": "^1.1.12" 33 | }, 34 | "devDependencies": { 35 | "@pika/pack": "^0.5.0", 36 | "@pika/plugin-build-node": "^0.9.2", 37 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 38 | "@types/node": "^10.12.18", 39 | "typescript": "^3.0.0" 40 | }, 41 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593" 42 | } 43 | -------------------------------------------------------------------------------- /packages/plugin-bundle-types/pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-bundle-types 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Bundle & tree-shake all TypeScript definitions into a single file. 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-bundle-types --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-bundle-types --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```json 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-ts-standard-pkg"], 26 | ["@pika/plugin-build-node"], 27 | ["@pika/plugin-bundle-types"] 28 | ] 29 | } 30 | } 31 | ``` 32 | 33 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 34 | 35 | ## Options 36 | 37 | - `"tsconfig"`: The relative path to the `tsconfig.json` config file to use. Defaults to the top-level project TypeScript config file, if one exists. 38 | - `"entrypoint"` (Default: `"types"`): Customize the package.json manifest entrypoint set by this plugin. Accepts either a string, an array of strings, or `null` to disable entrypoint. Changing this is not recommended for most usage. 39 | 40 | ## Result 41 | 42 | TODO -------------------------------------------------------------------------------- /packages/plugin-bundle-types/pkg/dist-node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } 6 | 7 | var path = _interopDefault(require('path')); 8 | var fs = _interopDefault(require('fs')); 9 | var rimraf = _interopDefault(require('rimraf')); 10 | var types = require('@pika/types'); 11 | var rollup = require('rollup'); 12 | var rollupPluginDts = _interopDefault(require('rollup-plugin-dts')); 13 | 14 | const DEFAULT_ENTRYPOINT = 'types'; 15 | async function beforeJob({ 16 | out 17 | }) { 18 | const typesDir = path.join(out, 'dist-types'); 19 | 20 | if (!fs.existsSync(typesDir)) { 21 | throw new types.MessageError('No "dist-types/" folder exists to bundle.'); 22 | } 23 | 24 | const typesEntrypoint = path.join(out, 'dist-types/index.d.ts'); 25 | 26 | if (!fs.existsSync(typesEntrypoint)) { 27 | throw new types.MessageError('A "dist-types/index.d.ts" entrypoint is required, but none was found.'); 28 | } 29 | } 30 | function manifest(manifest, { 31 | options 32 | }) { 33 | if (options.entrypoint !== null) { 34 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 35 | 36 | if (typeof keys === 'string') { 37 | keys = [keys]; 38 | } 39 | 40 | for (const key of keys) { 41 | manifest[key] = 'dist-types/index.d.ts'; 42 | } 43 | } 44 | } 45 | async function build({ 46 | out, 47 | options, 48 | reporter 49 | }) { 50 | const readFromTypes = path.join(out, 'dist-types', 'index.d.ts'); 51 | const writeToTypes = path.join(out, 'dist-types'); 52 | const writeToTypesBundled = path.join(writeToTypes, 'index.d.ts'); 53 | const result = await rollup.rollup({ 54 | input: readFromTypes, 55 | plugins: [rollupPluginDts()] 56 | }); 57 | rimraf.sync(writeToTypes); 58 | await result.write({ 59 | file: writeToTypesBundled, 60 | format: 'esm' 61 | }); 62 | reporter.created(writeToTypesBundled); 63 | } 64 | 65 | exports.beforeJob = beforeJob; 66 | exports.build = build; 67 | exports.manifest = manifest; 68 | //# sourceMappingURL=index.js.map 69 | -------------------------------------------------------------------------------- /packages/plugin-bundle-types/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import rimraf from 'rimraf'; 4 | import { MessageError } from '@pika/types'; 5 | import { rollup } from 'rollup'; 6 | import rollupPluginDts from 'rollup-plugin-dts'; 7 | const DEFAULT_ENTRYPOINT = 'types'; 8 | export async function beforeJob({ out }) { 9 | const typesDir = path.join(out, 'dist-types'); 10 | if (!fs.existsSync(typesDir)) { 11 | throw new MessageError('No "dist-types/" folder exists to bundle.'); 12 | } 13 | const typesEntrypoint = path.join(out, 'dist-types/index.d.ts'); 14 | if (!fs.existsSync(typesEntrypoint)) { 15 | throw new MessageError('A "dist-types/index.d.ts" entrypoint is required, but none was found.'); 16 | } 17 | } 18 | export function manifest(manifest, { options }) { 19 | if (options.entrypoint !== null) { 20 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 21 | if (typeof keys === 'string') { 22 | keys = [keys]; 23 | } 24 | for (const key of keys) { 25 | manifest[key] = 'dist-types/index.d.ts'; 26 | } 27 | } 28 | } 29 | export async function build({ out, options, reporter }) { 30 | const readFromTypes = path.join(out, 'dist-types', 'index.d.ts'); 31 | const writeToTypes = path.join(out, 'dist-types'); 32 | const writeToTypesBundled = path.join(writeToTypes, 'index.d.ts'); 33 | const result = await rollup({ 34 | input: readFromTypes, 35 | plugins: [rollupPluginDts()], 36 | }); 37 | rimraf.sync(writeToTypes); 38 | await result.write({ 39 | file: writeToTypesBundled, 40 | format: 'esm', 41 | }); 42 | reporter.created(writeToTypesBundled); 43 | } 44 | -------------------------------------------------------------------------------- /packages/plugin-bundle-types/pkg/dist-types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { BuilderOptions } from '@pika/types'; 2 | export declare function beforeJob({ out }: BuilderOptions): Promise; 3 | export declare function manifest(manifest: any, { options }: BuilderOptions): void; 4 | export declare function build({ out, options, reporter }: BuilderOptions): Promise; 5 | -------------------------------------------------------------------------------- /packages/plugin-bundle-types/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-bundle-types", 3 | "description": "A @pika/pack plugin: Bundle & tree-shake all TypeScript definitions into a single file.", 4 | "version": "0.9.2", 5 | "license": "MIT", 6 | "files": [ 7 | "dist-*/", 8 | "bin/" 9 | ], 10 | "pika": true, 11 | "sideEffects": false, 12 | "homepage": "https://www.pikapkg.com", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/pikapkg/builders.git" 16 | }, 17 | "dependencies": { 18 | "@pika/types": "^0.9.2", 19 | "rimraf": "^3.0.0", 20 | "rollup": "^2.3.0", 21 | "rollup-plugin-dts": "^1.1.12" 22 | }, 23 | "devDependencies": { 24 | "@pika/pack": "^0.5.0", 25 | "@pika/plugin-build-node": "^0.9.2", 26 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 27 | "@types/node": "^10.12.18", 28 | "typescript": "^3.0.0" 29 | }, 30 | "publishConfig": { 31 | "access": "public" 32 | }, 33 | "source": "dist-src/index.js", 34 | "types": "dist-types/index.d.ts", 35 | "main": "dist-node/index.js" 36 | } 37 | -------------------------------------------------------------------------------- /packages/plugin-bundle-types/src/index.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import rimraf from 'rimraf'; 4 | import {BuilderOptions, MessageError} from '@pika/types'; 5 | import {rollup} from 'rollup'; 6 | import rollupPluginDts from 'rollup-plugin-dts'; 7 | const DEFAULT_ENTRYPOINT = 'types'; 8 | 9 | export async function beforeJob({out}: BuilderOptions) { 10 | const typesDir = path.join(out, 'dist-types'); 11 | if (!fs.existsSync(typesDir)) { 12 | throw new MessageError('No "dist-types/" folder exists to bundle.'); 13 | } 14 | 15 | const typesEntrypoint = path.join(out, 'dist-types/index.d.ts'); 16 | if (!fs.existsSync(typesEntrypoint)) { 17 | throw new MessageError('A "dist-types/index.d.ts" entrypoint is required, but none was found.'); 18 | } 19 | } 20 | 21 | export function manifest(manifest, {options}: BuilderOptions) { 22 | if (options.entrypoint !== null) { 23 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 24 | if (typeof keys === 'string') { 25 | keys = [keys]; 26 | } 27 | for (const key of keys) { 28 | manifest[key] = 'dist-types/index.d.ts'; 29 | } 30 | } 31 | } 32 | 33 | export async function build({out, options, reporter}: BuilderOptions): Promise { 34 | const readFromTypes = path.join(out, 'dist-types', 'index.d.ts'); 35 | const writeToTypes = path.join(out, 'dist-types'); 36 | const writeToTypesBundled = path.join(writeToTypes, 'index.d.ts'); 37 | const result = await rollup({ 38 | input: readFromTypes, 39 | plugins: [rollupPluginDts()], 40 | }); 41 | rimraf.sync(writeToTypes); 42 | await result.write({ 43 | file: writeToTypesBundled, 44 | format: 'esm', 45 | }); 46 | reporter.created(writeToTypesBundled); 47 | } 48 | -------------------------------------------------------------------------------- /packages/plugin-bundle-types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["src"], 4 | "exclude": ["node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/plugin-bundle-web/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-bundle-web 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds a bundled Web distribution to your package, built & optimized to run in most web browsers (and bundlers). Useful for hosting on a CDN like UNPKG and/or when package dependencies aren't written to run natively on the web. 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-bundle-web --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-bundle-web --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```js 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-standard-pkg"], 26 | ["@pika/plugin-build-web"], // Required to precede in pipeline 27 | ["@pika/plugin-bundle-web", { /* options (optional) */ }] 28 | ] 29 | } 30 | } 31 | ``` 32 | 33 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 34 | 35 | ## Options 36 | 37 | - `"sourcemap"` (Default: `"true"`): Adds a [source map](https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) for this build. 38 | - `"browser"` (Default: `false`): If true, this plugin will respect the "browser" field in bundled dependencies over the usual "main" Node-specific entrypoint. This may be required for some dependencies, but may cause problems with others. YMMV. 39 | - `"namedExports"` (Default: `undefined`): Ecplicitly specify unresolvable named exports (See [`rollup-plugin-commonjs`](https://github.com/rollup/rollup-plugin-commonjs/tree/v9.2.0#custom-named-exports) for more information). 40 | - `"minify"` (Default: `true`): Specify if bundle should be minifed using [`terser`](https://github.com/terser-js/terser) or not. Can also be [`terser` options object](https://github.com/terser-js/terser#minify-options) to further tweak minification. 41 | - `"targets"` (Default: `{"esmodules": true}`): The browsers supported/targeted by the build. Defaults to support all browsers that support ES Module (ESM) syntax. 42 | - `"entrypoint"` (Default: `"browser"`): Customize the package.json manifest entrypoint set by this plugin. Accepts either a string, an array of strings, or `null` to disable entrypoint. Changing this is not recommended for most usage. 43 | - `{"entrypoint": "browser"}` will create an "browser" entrypoint that points to "dist-web/index.bundled.js". This is supported by both [`unpkg`](https://unpkg.com) and [`jsdelivr`](https://jsdelivr.com). 44 | - `{"entrypoint": ["unpkg", "jsdelivr"]}` will create both "unpkg" & "jsdelivr" "dist-web/index.bundled.js" entrypoints. 45 | 46 | ## Result 47 | 48 | 1. Adds a web bundled distribution to your built package: `dist-web/index.bundled.js` 49 | 1. ES Module (ESM) syntax 50 | 1. Transpiled to run on all browsers where ES Module syntax is supported. 51 | 1. All dependencies inlined into this file. 52 | 1. Minified using terser (Can optionally be skipped) 53 | 1. (if specified) Adds the file to your specified "entrypoint". 54 | 55 | Note that this does not add or modify the "module" entrypoint to your package.json. Bundles should continue to use the "module" entrypoint, while this build can be loaded directly in the browser (from a CDN like UNPKG). 56 | -------------------------------------------------------------------------------- /packages/plugin-bundle-web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-bundle-web", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: Adds a bundled Web distribution to your package, built & optimized to run in most web browsers (and bundlers).", 5 | "license": "MIT", 6 | "main": "pkg/dist-node/index.js", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "@pika/plugin-ts-standard-pkg" 19 | ], 20 | [ 21 | "@pika/plugin-build-node" 22 | ] 23 | ] 24 | }, 25 | "scripts": { 26 | "build": "pika-pack build" 27 | }, 28 | "dependencies": { 29 | "@babel/core": "^7.0.0", 30 | "@babel/plugin-syntax-dynamic-import": "^7.2.0", 31 | "@babel/plugin-syntax-import-meta": "^7.2.0", 32 | "@babel/preset-env": "^7.2.3", 33 | "@pika/types": "^0.9.2", 34 | "@rollup/plugin-commonjs": "^11.0.0", 35 | "@rollup/plugin-json": "^4.0.0", 36 | "@rollup/plugin-node-resolve": "^7.0.0", 37 | "rollup": "^2.3.0", 38 | "rollup-plugin-babel": "^4.3.0", 39 | "rollup-plugin-terser": "^5.1.1" 40 | }, 41 | "devDependencies": { 42 | "@pika/pack": "^0.5.0", 43 | "@pika/plugin-build-node": "^0.9.2", 44 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 45 | "@types/node": "^10.12.18", 46 | "typescript": "^3.0.0" 47 | }, 48 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593" 49 | } 50 | -------------------------------------------------------------------------------- /packages/plugin-bundle-web/pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-bundle-web 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds a bundled Web distribution to your package, built & optimized to run in most web browsers (and bundlers). Useful for hosting on a CDN like UNPKG and/or when package dependencies aren't written to run natively on the web. 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-bundle-web --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-bundle-web --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```js 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-standard-pkg"], 26 | ["@pika/plugin-build-web"], // Required to precede in pipeline 27 | ["@pika/plugin-bundle-web", { /* options (optional) */ }] 28 | ] 29 | } 30 | } 31 | ``` 32 | 33 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 34 | 35 | ## Options 36 | 37 | - `"sourcemap"` (Default: `"true"`): Adds a [source map](https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) for this build. 38 | - `"browser"` (Default: `false`): If true, this plugin will respect the "browser" field in bundled dependencies over the usual "main" Node-specific entrypoint. This may be required for some dependencies, but may cause problems with others. YMMV. 39 | - `"namedExports"` (Default: `undefined`): Ecplicitly specify unresolvable named exports (See [`rollup-plugin-commonjs`](https://github.com/rollup/rollup-plugin-commonjs/tree/v9.2.0#custom-named-exports) for more information). 40 | - `"minify"` (Default: `true`): Specify if bundle should be minifed using [`terser`](https://github.com/terser-js/terser) or not. Can also be [`terser` options object](https://github.com/terser-js/terser#minify-options) to further tweak minification. 41 | - `"targets"` (Default: `{"esmodules": true}`): The browsers supported/targeted by the build. Defaults to support all browsers that support ES Module (ESM) syntax. 42 | - `"entrypoint"` (Default: `"browser"`): Customize the package.json manifest entrypoint set by this plugin. Accepts either a string, an array of strings, or `null` to disable entrypoint. Changing this is not recommended for most usage. 43 | - `{"entrypoint": "browser"}` will create an "browser" entrypoint that points to "dist-web/index.bundled.js". This is supported by both [`unpkg`](https://unpkg.com) and [`jsdelivr`](https://jsdelivr.com). 44 | - `{"entrypoint": ["unpkg", "jsdelivr"]}` will create both "unpkg" & "jsdelivr" "dist-web/index.bundled.js" entrypoints. 45 | 46 | ## Result 47 | 48 | 1. Adds a web bundled distribution to your built package: `dist-web/index.bundled.js` 49 | 1. ES Module (ESM) syntax 50 | 1. Transpiled to run on all browsers where ES Module syntax is supported. 51 | 1. All dependencies inlined into this file. 52 | 1. Minified using terser (Can optionally be skipped) 53 | 1. (if specified) Adds the file to your specified "entrypoint". 54 | 55 | Note that this does not add or modify the "module" entrypoint to your package.json. Bundles should continue to use the "module" entrypoint, while this build can be loaded directly in the browser (from a CDN like UNPKG). 56 | -------------------------------------------------------------------------------- /packages/plugin-bundle-web/pkg/dist-node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } 6 | 7 | var rollupCommonJs = _interopDefault(require('@rollup/plugin-commonjs')); 8 | var rollupJson = _interopDefault(require('@rollup/plugin-json')); 9 | var rollupNodeResolve = _interopDefault(require('@rollup/plugin-node-resolve')); 10 | var rollupPluginTerser = require('rollup-plugin-terser'); 11 | var rollupBabel = _interopDefault(require('rollup-plugin-babel')); 12 | var babelPluginDynamicImportSyntax = _interopDefault(require('@babel/plugin-syntax-dynamic-import')); 13 | var babelPluginImportMetaSyntax = _interopDefault(require('@babel/plugin-syntax-import-meta')); 14 | var babelPresetEnv = _interopDefault(require('@babel/preset-env')); 15 | var path = _interopDefault(require('path')); 16 | var fs = _interopDefault(require('fs')); 17 | var types = require('@pika/types'); 18 | var rollup = require('rollup'); 19 | 20 | const DEFAULT_ENTRYPOINT = 'browser'; 21 | async function beforeJob({ 22 | out 23 | }) { 24 | const srcDirectory = path.join(out, 'dist-web/'); 25 | 26 | if (!fs.existsSync(srcDirectory)) { 27 | throw new types.MessageError('"dist-web/" does not exist. "plugin-bundle-web" requires "plugin-build-dev" to precede in pipeline.'); 28 | } 29 | 30 | const srcEntrypoint = path.join(out, 'dist-web/index.js'); 31 | 32 | if (!fs.existsSync(srcEntrypoint)) { 33 | throw new types.MessageError('"dist-web/index.js" is the expected standard entrypoint, but it does not exist.'); 34 | } 35 | } 36 | function manifest(manifest, { 37 | options 38 | }) { 39 | if (options.entrypoint !== null) { 40 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 41 | 42 | if (typeof keys === 'string') { 43 | keys = [keys]; 44 | } 45 | 46 | for (const key of keys) { 47 | manifest[key] = manifest[key] || 'dist-web/index.bundled.js'; 48 | } 49 | } 50 | } 51 | async function build({ 52 | out, 53 | options, 54 | reporter 55 | }) { 56 | const readFromWeb = path.join(out, 'dist-web', 'index.js'); 57 | const writeToWeb = path.join(out, 'dist-web'); 58 | const writeToWebBundled = path.join(writeToWeb, 'index.bundled.js'); 59 | const result = await rollup.rollup({ 60 | input: readFromWeb, 61 | plugins: [rollupNodeResolve({ 62 | preferBuiltins: true, 63 | browser: !!options.browser 64 | }), rollupCommonJs({ 65 | include: 'node_modules/**', 66 | sourceMap: false, 67 | namedExports: options.namedExports 68 | }), rollupJson({ 69 | include: 'node_modules/**', 70 | compact: true 71 | }), rollupBabel({ 72 | babelrc: false, 73 | compact: false, 74 | presets: [[babelPresetEnv, { 75 | modules: false, 76 | targets: options.targets || { 77 | esmodules: true 78 | } 79 | }]], 80 | plugins: [babelPluginDynamicImportSyntax, babelPluginImportMetaSyntax] 81 | }), options.minify !== false ? rollupPluginTerser.terser(typeof options.minify === 'object' ? options.minify : undefined) : {}] 82 | }); 83 | await result.write({ 84 | dir: writeToWeb, 85 | entryFileNames: '[name].bundled.js', 86 | chunkFileNames: '[name]-[hash].bundled.js', 87 | format: 'esm', 88 | exports: 'named', 89 | sourcemap: options.sourcemap === undefined ? true : options.sourcemap 90 | }); 91 | reporter.created(writeToWebBundled); 92 | } 93 | 94 | exports.beforeJob = beforeJob; 95 | exports.build = build; 96 | exports.manifest = manifest; 97 | //# sourceMappingURL=index.js.map 98 | -------------------------------------------------------------------------------- /packages/plugin-bundle-web/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | import rollupCommonJs from '@rollup/plugin-commonjs'; 2 | import rollupJson from '@rollup/plugin-json'; 3 | import rollupNodeResolve from '@rollup/plugin-node-resolve'; 4 | import { terser as rollupTerser } from 'rollup-plugin-terser'; 5 | import rollupBabel from 'rollup-plugin-babel'; 6 | import babelPluginDynamicImportSyntax from '@babel/plugin-syntax-dynamic-import'; 7 | import babelPluginImportMetaSyntax from '@babel/plugin-syntax-import-meta'; 8 | import babelPresetEnv from '@babel/preset-env'; 9 | import path from 'path'; 10 | import fs from 'fs'; 11 | import { MessageError } from '@pika/types'; 12 | import { rollup } from 'rollup'; 13 | const DEFAULT_ENTRYPOINT = 'browser'; 14 | export async function beforeJob({ out }) { 15 | const srcDirectory = path.join(out, 'dist-web/'); 16 | if (!fs.existsSync(srcDirectory)) { 17 | throw new MessageError('"dist-web/" does not exist. "plugin-bundle-web" requires "plugin-build-dev" to precede in pipeline.'); 18 | } 19 | const srcEntrypoint = path.join(out, 'dist-web/index.js'); 20 | if (!fs.existsSync(srcEntrypoint)) { 21 | throw new MessageError('"dist-web/index.js" is the expected standard entrypoint, but it does not exist.'); 22 | } 23 | } 24 | export function manifest(manifest, { options }) { 25 | if (options.entrypoint !== null) { 26 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 27 | if (typeof keys === 'string') { 28 | keys = [keys]; 29 | } 30 | for (const key of keys) { 31 | manifest[key] = manifest[key] || 'dist-web/index.bundled.js'; 32 | } 33 | } 34 | } 35 | export async function build({ out, options, reporter }) { 36 | const readFromWeb = path.join(out, 'dist-web', 'index.js'); 37 | const writeToWeb = path.join(out, 'dist-web'); 38 | const writeToWebBundled = path.join(writeToWeb, 'index.bundled.js'); 39 | const result = await rollup({ 40 | input: readFromWeb, 41 | plugins: [ 42 | rollupNodeResolve({ 43 | preferBuiltins: true, 44 | browser: !!options.browser, 45 | }), 46 | rollupCommonJs({ 47 | include: 'node_modules/**', 48 | sourceMap: false, 49 | namedExports: options.namedExports, 50 | }), 51 | rollupJson({ 52 | include: 'node_modules/**', 53 | compact: true, 54 | }), 55 | rollupBabel({ 56 | babelrc: false, 57 | compact: false, 58 | presets: [ 59 | [ 60 | babelPresetEnv, 61 | { 62 | modules: false, 63 | targets: options.targets || { esmodules: true }, 64 | }, 65 | ], 66 | ], 67 | plugins: [babelPluginDynamicImportSyntax, babelPluginImportMetaSyntax], 68 | }), 69 | options.minify !== false ? rollupTerser(typeof options.minify === 'object' ? options.minify : undefined) : {}, 70 | ], 71 | }); 72 | await result.write({ 73 | dir: writeToWeb, 74 | entryFileNames: '[name].bundled.js', 75 | chunkFileNames: '[name]-[hash].bundled.js', 76 | format: 'esm', 77 | exports: 'named', 78 | sourcemap: options.sourcemap === undefined ? true : options.sourcemap, 79 | }); 80 | reporter.created(writeToWebBundled); 81 | } 82 | -------------------------------------------------------------------------------- /packages/plugin-bundle-web/pkg/dist-types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { BuilderOptions } from '@pika/types'; 2 | export declare function beforeJob({ out }: BuilderOptions): Promise; 3 | export declare function manifest(manifest: any, { options }: BuilderOptions): void; 4 | export declare function build({ out, options, reporter }: BuilderOptions): Promise; 5 | -------------------------------------------------------------------------------- /packages/plugin-bundle-web/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-bundle-web", 3 | "description": "A @pika/pack plugin: Adds a bundled Web distribution to your package, built & optimized to run in most web browsers (and bundlers).", 4 | "version": "0.9.2", 5 | "license": "MIT", 6 | "files": [ 7 | "dist-*/", 8 | "bin/" 9 | ], 10 | "pika": true, 11 | "sideEffects": false, 12 | "homepage": "https://www.pikapkg.com", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/pikapkg/builders.git" 16 | }, 17 | "dependencies": { 18 | "@babel/core": "^7.0.0", 19 | "@babel/plugin-syntax-dynamic-import": "^7.2.0", 20 | "@babel/plugin-syntax-import-meta": "^7.2.0", 21 | "@babel/preset-env": "^7.2.3", 22 | "@pika/types": "^0.9.2", 23 | "@rollup/plugin-commonjs": "^11.0.0", 24 | "@rollup/plugin-json": "^4.0.0", 25 | "@rollup/plugin-node-resolve": "^7.0.0", 26 | "rollup": "^2.3.0", 27 | "rollup-plugin-babel": "^4.3.0", 28 | "rollup-plugin-terser": "^5.1.1" 29 | }, 30 | "devDependencies": { 31 | "@pika/pack": "^0.5.0", 32 | "@pika/plugin-build-node": "^0.9.2", 33 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 34 | "@types/node": "^10.12.18", 35 | "typescript": "^3.0.0" 36 | }, 37 | "publishConfig": { 38 | "access": "public" 39 | }, 40 | "source": "dist-src/index.js", 41 | "types": "dist-types/index.d.ts", 42 | "main": "dist-node/index.js" 43 | } 44 | -------------------------------------------------------------------------------- /packages/plugin-bundle-web/src/index.ts: -------------------------------------------------------------------------------- 1 | import rollupCommonJs from '@rollup/plugin-commonjs'; 2 | import rollupJson from '@rollup/plugin-json'; 3 | import rollupNodeResolve from '@rollup/plugin-node-resolve'; 4 | import {terser as rollupTerser} from 'rollup-plugin-terser'; 5 | import rollupBabel from 'rollup-plugin-babel'; 6 | import babelPluginDynamicImportSyntax from '@babel/plugin-syntax-dynamic-import'; 7 | import babelPluginImportMetaSyntax from '@babel/plugin-syntax-import-meta'; 8 | import babelPresetEnv from '@babel/preset-env'; 9 | 10 | import path from 'path'; 11 | import fs from 'fs'; 12 | import {BuilderOptions, MessageError} from '@pika/types'; 13 | import {rollup} from 'rollup'; 14 | 15 | const DEFAULT_ENTRYPOINT = 'browser'; 16 | 17 | export async function beforeJob({out}: BuilderOptions) { 18 | const srcDirectory = path.join(out, 'dist-web/'); 19 | if (!fs.existsSync(srcDirectory)) { 20 | throw new MessageError( 21 | '"dist-web/" does not exist. "plugin-bundle-web" requires "plugin-build-web" to precede in pipeline.', 22 | ); 23 | } 24 | const srcEntrypoint = path.join(out, 'dist-web/index.js'); 25 | if (!fs.existsSync(srcEntrypoint)) { 26 | throw new MessageError('"dist-web/index.js" is the expected standard entrypoint, but it does not exist.'); 27 | } 28 | } 29 | 30 | export function manifest(manifest, {options}: BuilderOptions) { 31 | if(options.entrypoint !== null) { 32 | let keys = options.entrypoint || [DEFAULT_ENTRYPOINT]; 33 | if (typeof keys === 'string') { 34 | keys = [keys]; 35 | } 36 | for (const key of keys) { 37 | manifest[key] = manifest[key] || 'dist-web/index.bundled.js'; 38 | } 39 | } 40 | } 41 | 42 | export async function build({out, options, reporter}: BuilderOptions): Promise { 43 | const readFromWeb = path.join(out, 'dist-web', 'index.js'); 44 | const writeToWeb = path.join(out, 'dist-web'); 45 | const writeToWebBundled = path.join(writeToWeb, 'index.bundled.js'); 46 | const result = await rollup({ 47 | input: readFromWeb, 48 | plugins: [ 49 | rollupNodeResolve({ 50 | preferBuiltins: true, 51 | browser: !!options.browser, 52 | }), 53 | rollupCommonJs({ 54 | include: 'node_modules/**', 55 | sourceMap: false, 56 | namedExports: options.namedExports, 57 | }), 58 | rollupJson({ 59 | include: 'node_modules/**', 60 | compact: true, 61 | }) as any, 62 | rollupBabel({ 63 | babelrc: false, 64 | compact: false, 65 | presets: [ 66 | [ 67 | babelPresetEnv, 68 | { 69 | modules: false, 70 | targets: options.targets || {esmodules: true}, 71 | }, 72 | ], 73 | ], 74 | plugins: [babelPluginDynamicImportSyntax, babelPluginImportMetaSyntax], 75 | }), 76 | options.minify !== false ? rollupTerser(typeof options.minify === 'object' ? options.minify : undefined) : {}, 77 | ], 78 | }); 79 | 80 | await result.write({ 81 | dir: writeToWeb, 82 | entryFileNames: '[name].bundled.js', 83 | chunkFileNames: '[name]-[hash].bundled.js', 84 | format: 'esm', 85 | exports: 'named', 86 | sourcemap: options.sourcemap === undefined ? true : options.sourcemap, 87 | }); 88 | reporter.created(writeToWebBundled); 89 | } 90 | -------------------------------------------------------------------------------- /packages/plugin-bundle-web/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["src"], 4 | "exclude": ["node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/plugin-copy-assets/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-copy-assets 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Copies static assets from your root source directory into the built `pkg/` directory. Useful for non-JS associated files (like CSS, images). 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-copy-assets --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-copy-assets --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```json 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-standard-pkg"], 26 | ["@pika/plugin-build-node", {}] 27 | ["@pika/plugin-copy-assets", {}] 28 | ] 29 | } 30 | } 31 | ``` 32 | 33 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 34 | 35 | 36 | ## Options 37 | 38 | - `"files"` (Default: `["assets/"]`): An array of files/folders to copy into the pkg out directory. Does not support glob pattern matching, but will copy any directories recursively. 39 | 40 | 41 | ## Result 42 | 43 | 1. See the package description. Copies static assets from your root source directory into the built `pkg/` directory (example: "assets/" => "pkg/assets"). -------------------------------------------------------------------------------- /packages/plugin-copy-assets/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-copy-assets", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: Copies static assets into your built package directory.", 5 | "license": "MIT", 6 | "main": "pkg/dist-node/index.js", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "@pika/plugin-ts-standard-pkg" 19 | ], 20 | [ 21 | "@pika/plugin-build-node" 22 | ] 23 | ] 24 | }, 25 | "scripts": { 26 | "build": "pika-pack build" 27 | }, 28 | "dependencies": { 29 | "@pika/types": "^0.9.2", 30 | "copy-concurrently": "^1.0.5" 31 | }, 32 | "devDependencies": { 33 | "@pika/pack": "^0.5.0", 34 | "@pika/plugin-build-node": "^0.9.2", 35 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 36 | "@types/node": "^10.12.18", 37 | "typescript": "^3.0.0" 38 | }, 39 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593" 40 | } 41 | -------------------------------------------------------------------------------- /packages/plugin-copy-assets/pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-copy-assets 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Copies static assets from your root source directory into the built `pkg/` directory. Useful for non-JS associated files (like CSS, images). 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-copy-assets --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-copy-assets --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```json 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-standard-pkg"], 26 | ["@pika/plugin-build-node", {}] 27 | ["@pika/plugin-copy-assets", {}] 28 | ] 29 | } 30 | } 31 | ``` 32 | 33 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 34 | 35 | 36 | ## Options 37 | 38 | - `"files"` (Default: `["assets/"]`): An array of files/folders to copy into the pkg out directory. Does not support glob pattern matching, but will copy any directories recursively. 39 | 40 | 41 | ## Result 42 | 43 | 1. See the package description. Copies static assets from your root source directory into the built `pkg/` directory (example: "assets/" => "pkg/assets"). -------------------------------------------------------------------------------- /packages/plugin-copy-assets/pkg/dist-node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } 6 | 7 | var copy = _interopDefault(require('copy-concurrently')); 8 | var path = _interopDefault(require('path')); 9 | var fs = _interopDefault(require('fs')); 10 | var types = require('@pika/types'); 11 | 12 | function manifest(manifest, { 13 | options 14 | }) { 15 | const files = options.files || ['assets/']; 16 | manifest.files = (manifest.files || []).concat(files); 17 | } 18 | async function beforeJob({ 19 | cwd, 20 | options 21 | }) { 22 | const files = options.files || ['assets/']; 23 | 24 | for (const fileRel of files) { 25 | const fileLoc = path.join(cwd, fileRel); 26 | 27 | if (!fs.existsSync(fileLoc)) { 28 | throw new types.MessageError(`"${fileRel}" does not exist.`); 29 | } 30 | } 31 | } 32 | async function build({ 33 | out, 34 | cwd, 35 | reporter, 36 | options 37 | }) { 38 | const files = options.files || ['assets/']; 39 | 40 | for (const fileRel of files) { 41 | const fileLoc = path.join(cwd, fileRel); 42 | const writeToLoc = path.join(out, fileRel); 43 | reporter.info(`copying ${fileRel}...`); 44 | await copy(fileLoc, writeToLoc); 45 | } 46 | } 47 | 48 | exports.beforeJob = beforeJob; 49 | exports.build = build; 50 | exports.manifest = manifest; 51 | //# sourceMappingURL=index.js.map 52 | -------------------------------------------------------------------------------- /packages/plugin-copy-assets/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | import copy from 'copy-concurrently'; 2 | import path from 'path'; 3 | import fs from 'fs'; 4 | import { MessageError } from '@pika/types'; 5 | export function manifest(manifest, { options }) { 6 | const files = options.files || ['assets/']; 7 | manifest.files = (manifest.files || []).concat(files); 8 | } 9 | export async function beforeJob({ cwd, options }) { 10 | const files = options.files || ['assets/']; 11 | for (const fileRel of files) { 12 | const fileLoc = path.join(cwd, fileRel); 13 | if (!fs.existsSync(fileLoc)) { 14 | throw new MessageError(`"${fileRel}" does not exist.`); 15 | } 16 | } 17 | } 18 | export async function build({ out, cwd, reporter, options }) { 19 | const files = options.files || ['assets/']; 20 | for (const fileRel of files) { 21 | const fileLoc = path.join(cwd, fileRel); 22 | const writeToLoc = path.join(out, fileRel); 23 | reporter.info(`copying ${fileRel}...`); 24 | await copy(fileLoc, writeToLoc); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/plugin-copy-assets/pkg/dist-types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { BuilderOptions } from '@pika/types'; 2 | export declare function manifest(manifest: any, { options }: BuilderOptions): void; 3 | export declare function beforeJob({ cwd, options }: BuilderOptions): Promise; 4 | export declare function build({ out, cwd, reporter, options }: BuilderOptions): Promise; 5 | -------------------------------------------------------------------------------- /packages/plugin-copy-assets/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-copy-assets", 3 | "description": "A @pika/pack plugin: Copies static assets into your built package directory.", 4 | "version": "0.9.2", 5 | "license": "MIT", 6 | "files": [ 7 | "dist-*/", 8 | "bin/" 9 | ], 10 | "pika": true, 11 | "sideEffects": false, 12 | "homepage": "https://www.pikapkg.com", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/pikapkg/builders.git" 16 | }, 17 | "dependencies": { 18 | "@pika/types": "^0.9.2", 19 | "copy-concurrently": "^1.0.5" 20 | }, 21 | "devDependencies": { 22 | "@pika/pack": "^0.5.0", 23 | "@pika/plugin-build-node": "^0.9.2", 24 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 25 | "@types/node": "^10.12.18", 26 | "typescript": "^3.0.0" 27 | }, 28 | "publishConfig": { 29 | "access": "public" 30 | }, 31 | "source": "dist-src/index.js", 32 | "types": "dist-types/index.d.ts", 33 | "main": "dist-node/index.js" 34 | } 35 | -------------------------------------------------------------------------------- /packages/plugin-copy-assets/src/index.ts: -------------------------------------------------------------------------------- 1 | import copy from 'copy-concurrently'; 2 | import path from 'path'; 3 | import fs from 'fs'; 4 | import {BuilderOptions, MessageError} from '@pika/types'; 5 | 6 | export function manifest(manifest, {options}: BuilderOptions) { 7 | const files = options.files || ['assets/']; 8 | manifest.files = (manifest.files || []).concat(files); 9 | } 10 | 11 | export async function beforeJob({cwd, options}: BuilderOptions) { 12 | const files = options.files || ['assets/']; 13 | for (const fileRel of files) { 14 | const fileLoc = path.join(cwd, fileRel); 15 | if (!fs.existsSync(fileLoc)) { 16 | throw new MessageError(`"${fileRel}" does not exist.`); 17 | } 18 | } 19 | } 20 | 21 | export async function build({out, cwd, reporter, options}: BuilderOptions): Promise { 22 | const files = options.files || ['assets/']; 23 | for (const fileRel of files) { 24 | const fileLoc = path.join(cwd, fileRel); 25 | const writeToLoc = path.join(out, fileRel); 26 | reporter.info(`copying ${fileRel}...`); 27 | await copy(fileLoc, writeToLoc); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/plugin-copy-assets/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["src"], 4 | "exclude": ["node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/plugin-simple-bin/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-simple-bin 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds a simple CLI wrapper to your package and properly configures your package.json `"bin"` field to point to it. Useful for quickly adding a command line interface to your library. 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-simple-bin --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-simple-bin --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```json 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-standard-pkg"], 26 | ["@pika/plugin-build-node"], 27 | ["@pika/plugin-simple-bin", {"bin": "my-cli"}] 28 | ] 29 | } 30 | } 31 | ``` 32 | 33 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 34 | 35 | 36 | ## Result 37 | 38 | 1. Adds a simple bin/CLI wrapper to your built package: `dist-node/index.bin.js` 39 | 1. Built for Node.js 40 | 1. Loads your library, and calls an exported `run()` method with the CLI args. 41 | 1. Will load a bundled Node.js distribution if one exists. 42 | 1. Configures the built package.json with a new `"bin"` entrypoint, so that npm knows to install your package as a CLI. -------------------------------------------------------------------------------- /packages/plugin-simple-bin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-simple-bin", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: Adds a simple CLI wrapper.", 5 | "license": "MIT", 6 | "main": "pkg/dist-node/index.js", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "@pika/plugin-standard-pkg" 19 | ], 20 | [ 21 | "@pika/plugin-build-types" 22 | ], 23 | [ 24 | "@pika/plugin-build-node" 25 | ] 26 | ] 27 | }, 28 | "scripts": { 29 | "build": "pika-pack build" 30 | }, 31 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593", 32 | "dependencies": { 33 | "@pika/types": "^0.9.2" 34 | }, 35 | "devDependencies": { 36 | "@pika/pack": "^0.5.0", 37 | "@pika/plugin-build-node": "^0.9.2", 38 | "@pika/plugin-build-types": "^0.9.2", 39 | "@pika/plugin-standard-pkg": "^0.9.2", 40 | "@types/node": "^10.12.18", 41 | "typescript": "^3.7.0" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/plugin-simple-bin/pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-simple-bin 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds a simple CLI wrapper to your package and properly configures your package.json `"bin"` field to point to it. Useful for quickly adding a command line interface to your library. 5 | 6 | 7 | ## Install 8 | 9 | ```sh 10 | # npm: 11 | npm install @pika/plugin-simple-bin --save-dev 12 | # yarn: 13 | yarn add @pika/plugin-simple-bin --dev 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```json 20 | { 21 | "name": "example-package-json", 22 | "version": "1.0.0", 23 | "@pika/pack": { 24 | "pipeline": [ 25 | ["@pika/plugin-standard-pkg"], 26 | ["@pika/plugin-build-node"], 27 | ["@pika/plugin-simple-bin", {"bin": "my-cli"}] 28 | ] 29 | } 30 | } 31 | ``` 32 | 33 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 34 | 35 | 36 | ## Result 37 | 38 | 1. Adds a simple bin/CLI wrapper to your built package: `dist-node/index.bin.js` 39 | 1. Built for Node.js 40 | 1. Loads your library, and calls an exported `run()` method with the CLI args. 41 | 1. Will load a bundled Node.js distribution if one exists. 42 | 1. Configures the built package.json with a new `"bin"` entrypoint, so that npm knows to install your package as a CLI. -------------------------------------------------------------------------------- /packages/plugin-simple-bin/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import { MessageError } from '@pika/types'; 4 | const BIN_FILENAME = 'dist-node/index.bin.js'; 5 | export function beforeBuild({ 6 | options 7 | }) { 8 | if (!options.bin) { 9 | return new MessageError('option "bin" must be defined. Example: {"bin": "example-cli"}'); 10 | } 11 | } 12 | export async function beforeJob({ 13 | out 14 | }) { 15 | const nodeDirectory = path.join(out, 'dist-node'); 16 | 17 | if (!fs.existsSync(nodeDirectory)) { 18 | throw new MessageError('"dist-node/" does not exist, or was not yet created in the pipeline.'); 19 | } 20 | 21 | const nodeEntrypoint = path.join(out, 'dist-node/index.js'); 22 | 23 | if (!fs.existsSync(nodeEntrypoint)) { 24 | throw new MessageError('"dist-node/index.js" is the expected standard entrypoint, but it does not exist.'); 25 | } 26 | 27 | const testModuleInterface = await import(nodeEntrypoint); 28 | 29 | if (!(testModuleInterface.run || testModuleInterface.cli || testModuleInterface.default)) { 30 | throw new MessageError('"dist-node/index.js" must export a "run", "cli", or "default" function for the CLI to run.'); 31 | } 32 | } 33 | export function manifest(newManifest, { 34 | options 35 | }) { 36 | const { 37 | bin 38 | } = options; 39 | newManifest.bin = newManifest.bin || {}; 40 | newManifest.bin[bin] = BIN_FILENAME; 41 | return newManifest; 42 | } 43 | export function build({ 44 | out, 45 | cwd, 46 | options, 47 | reporter 48 | }) { 49 | const { 50 | minNodeVersion, 51 | v8CompileCache 52 | } = options; 53 | const binFilename = path.join(out, BIN_FILENAME); 54 | 55 | if (v8CompileCache) { 56 | const v8CompileCacheRead = path.join(cwd, 'node_modules/v8-compile-cache/v8-compile-cache.js'); 57 | const v8CompileCacheWrite = path.join(out, 'dist-node/v8-compile-cache.js'); 58 | fs.copyFileSync(v8CompileCacheRead, v8CompileCacheWrite); 59 | } 60 | 61 | fs.writeFileSync(binFilename, `#!/usr/bin/env node 62 | 'use strict'; 63 | ${minNodeVersion ? ` 64 | const ver = process.versions.node; 65 | const majorVer = parseInt(ver.split('.')[0], 10); 66 | 67 | if (majorVer < ${minNodeVersion}) { 68 | console.error('Node version ' + ver + ' is not supported, please use Node.js ${minNodeVersion}.0 or higher.'); 69 | process.exit(1); 70 | } 71 | ` : ``}${v8CompileCache ? ` 72 | try { 73 | require('./v8-compile-cache.js'); 74 | } catch (err) { 75 | // We don't have/need this on legacy builds and dev builds 76 | } 77 | ` : ``} 78 | let hasBundled = true 79 | 80 | try { 81 | require.resolve('./index.bundled.js'); 82 | } catch(err) { 83 | // We don't have/need this on legacy builds and dev builds 84 | // If an error happens here, throw it, that means no Node.js distribution exists at all. 85 | hasBundled = false; 86 | } 87 | 88 | const cli = !hasBundled ? require('../') : require('./index.bundled.js'); 89 | 90 | if (cli.autoRun) { 91 | return; 92 | } 93 | 94 | const run = cli.run || cli.cli || cli.default; 95 | run(process.argv).catch(function (error) { 96 | console.error(\`\n\$\{error.stack || error.message || error\}\n\`); 97 | process.exit(1); 98 | }); 99 | `); 100 | fs.chmodSync(binFilename, '755'); 101 | reporter.created(path.join(out, BIN_FILENAME), `bin.${options.bin}`); 102 | } -------------------------------------------------------------------------------- /packages/plugin-simple-bin/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-simple-bin", 3 | "description": "A @pika/pack plugin: Adds a simple CLI wrapper.", 4 | "version": "0.9.2", 5 | "license": "MIT", 6 | "files": [ 7 | "dist-*/", 8 | "bin/" 9 | ], 10 | "pika": true, 11 | "sideEffects": false, 12 | "homepage": "https://www.pikapkg.com", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/pikapkg/builders.git" 16 | }, 17 | "dependencies": { 18 | "@pika/types": "^0.9.2" 19 | }, 20 | "devDependencies": { 21 | "@pika/pack": "^0.5.0", 22 | "@pika/plugin-build-node": "^0.9.2", 23 | "@pika/plugin-build-types": "^0.9.2", 24 | "@pika/plugin-standard-pkg": "^0.9.2", 25 | "@types/node": "^10.12.18", 26 | "typescript": "^3.7.0" 27 | }, 28 | "publishConfig": { 29 | "access": "public" 30 | }, 31 | "esnext": "dist-src/index.js", 32 | "types": "dist-types/index.d.ts", 33 | "main": "dist-node/index.js" 34 | } 35 | -------------------------------------------------------------------------------- /packages/plugin-simple-bin/src/index.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import {MessageError} from '@pika/types'; 4 | const BIN_FILENAME = 'dist-node/index.bin.js'; 5 | 6 | export function beforeBuild({options}) { 7 | if (!options.bin) { 8 | return new MessageError('option "bin" must be defined. Example: {"bin": "example-cli"}'); 9 | } 10 | } 11 | 12 | export async function beforeJob({out}) { 13 | const nodeDirectory = path.join(out, 'dist-node'); 14 | if (!fs.existsSync(nodeDirectory)) { 15 | throw new MessageError('"dist-node/" does not exist, or was not yet created in the pipeline.'); 16 | } 17 | const nodeEntrypoint = path.join(out, 'dist-node/index.js'); 18 | if (!fs.existsSync(nodeEntrypoint)) { 19 | throw new MessageError('"dist-node/index.js" is the expected standard entrypoint, but it does not exist.'); 20 | } 21 | const testModuleInterface = await import(nodeEntrypoint); 22 | if (!(testModuleInterface.run || testModuleInterface.cli || testModuleInterface.default)) { 23 | throw new MessageError( 24 | '"dist-node/index.js" must export a "run", "cli", or "default" function for the CLI to run.', 25 | ); 26 | } 27 | } 28 | 29 | export function manifest(newManifest, {options}) { 30 | const {bin} = options; 31 | newManifest.bin = newManifest.bin || {}; 32 | newManifest.bin[bin] = BIN_FILENAME; 33 | return newManifest; 34 | } 35 | 36 | export function build({out, cwd, options, reporter}) { 37 | const {minNodeVersion, v8CompileCache} = options; 38 | const binFilename = path.join(out, BIN_FILENAME); 39 | if (v8CompileCache) { 40 | const v8CompileCacheRead = path.join(cwd, 'node_modules/v8-compile-cache/v8-compile-cache.js'); 41 | const v8CompileCacheWrite = path.join(out, 'dist-node/v8-compile-cache.js'); 42 | fs.copyFileSync(v8CompileCacheRead, v8CompileCacheWrite); 43 | } 44 | 45 | fs.writeFileSync( 46 | binFilename, 47 | `#!/usr/bin/env node 48 | 'use strict'; 49 | ${ 50 | minNodeVersion 51 | ? ` 52 | const ver = process.versions.node; 53 | const majorVer = parseInt(ver.split('.')[0], 10); 54 | 55 | if (majorVer < ${minNodeVersion}) { 56 | console.error('Node version ' + ver + ' is not supported, please use Node.js ${minNodeVersion}.0 or higher.'); 57 | process.exit(1); 58 | } 59 | ` 60 | : `` 61 | }${ 62 | v8CompileCache 63 | ? ` 64 | try { 65 | require('./v8-compile-cache.js'); 66 | } catch (err) { 67 | // We don't have/need this on legacy builds and dev builds 68 | } 69 | ` 70 | : `` 71 | } 72 | let hasBundled = true 73 | 74 | try { 75 | require.resolve('./index.bundled.js'); 76 | } catch(err) { 77 | // We don't have/need this on legacy builds and dev builds 78 | // If an error happens here, throw it, that means no Node.js distribution exists at all. 79 | hasBundled = false; 80 | } 81 | 82 | const cli = !hasBundled ? require('../') : require('./index.bundled.js'); 83 | 84 | if (cli.autoRun) { 85 | return; 86 | } 87 | 88 | const run = cli.run || cli.cli || cli.default; 89 | run(process.argv).catch(function (error) { 90 | console.error(\`\n\$\{error.stack || error.message || error\}\n\`); 91 | process.exit(1); 92 | }); 93 | `, 94 | ); 95 | 96 | fs.chmodSync(binFilename, '755'); 97 | reporter.created(path.join(out, BIN_FILENAME), `bin.${options.bin}`); 98 | } 99 | -------------------------------------------------------------------------------- /packages/plugin-simple-bin/tsconfig.json: -------------------------------------------------------------------------------- 1 | {"include": ["src"]} -------------------------------------------------------------------------------- /packages/plugin-source-bucklescript/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-source-bucklescript 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Builds ES2018 JavaScript from ReasonML or OCaml via [BuckleScript](https://bucklescript.github.io). 5 | 6 | 7 | 8 | 9 | ## Install 10 | 11 | ```sh 12 | # npm: 13 | npm install @pika/plugin-source-bucklescript --save-dev 14 | # yarn: 15 | yarn add @pika/plugin-source-bucklescript --dev 16 | ``` 17 | 18 | 19 | ## Usage 20 | 21 | ```json 22 | { 23 | "name": "example-package-json", 24 | "version": "1.0.0", 25 | "@pika/pack": { 26 | "pipeline": [ 27 | ["@pika/plugin-source-bucklescript"], 28 | ["@pika/plugin-build-node"], 29 | ["@pika/plugin-build-web"], 30 | ["@pika/plugin-build-types"] 31 | ] 32 | } 33 | } 34 | ``` 35 | 36 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 37 | 38 | 39 | ## Result 40 | 41 | Unlike other build plugins, this plugin reads directly from your package `src/` directory. Make sure your code exists in a `src/` directory, with an `src/index.ml` or `src/index.re` file acting as your package entrypoint. 42 | 43 | Other build plugins will depend on the resulting distribution, so include this plugin early in your build pipeline for others to use. 44 | 45 | 1. Adds a modern ES2018 distribution to your built package: `dist-src/` 46 | 1. Adds an "esnext" entrypoint to your built `package.json` manifest. 47 | -------------------------------------------------------------------------------- /packages/plugin-source-bucklescript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-source-bucklescript", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: ", 5 | "license": "MIT", 6 | "main": "pkg/dist-node/index.js", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "@pika/plugin-ts-standard-pkg" 19 | ], 20 | [ 21 | "@pika/plugin-build-node" 22 | ] 23 | ] 24 | }, 25 | "scripts": { 26 | "build": "pika-pack build" 27 | }, 28 | "peerDependencies": { 29 | "bs-platform": "*" 30 | }, 31 | "dependencies": { 32 | "@pika/types": "^0.9.2", 33 | "rollup": "^2.3.0", 34 | "rollup-plugin-bucklescript": "^0.7.0" 35 | }, 36 | "devDependencies": { 37 | "@pika/pack": "^0.5.0", 38 | "@pika/plugin-build-node": "^0.9.2", 39 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 40 | "@types/node": "^10.12.18", 41 | "typescript": "^3.0.0" 42 | }, 43 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593" 44 | } 45 | -------------------------------------------------------------------------------- /packages/plugin-source-bucklescript/pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-source-bucklescript 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Builds ES2018 JavaScript from ReasonML or OCaml via [BuckleScript](https://bucklescript.github.io). 5 | 6 | 7 | 8 | 9 | ## Install 10 | 11 | ```sh 12 | # npm: 13 | npm install @pika/plugin-source-bucklescript --save-dev 14 | # yarn: 15 | yarn add @pika/plugin-source-bucklescript --dev 16 | ``` 17 | 18 | 19 | ## Usage 20 | 21 | ```json 22 | { 23 | "name": "example-package-json", 24 | "version": "1.0.0", 25 | "@pika/pack": { 26 | "pipeline": [ 27 | ["@pika/plugin-source-bucklescript"], 28 | ["@pika/plugin-build-node"], 29 | ["@pika/plugin-build-web"], 30 | ["@pika/plugin-build-types"] 31 | ] 32 | } 33 | } 34 | ``` 35 | 36 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 37 | 38 | 39 | ## Result 40 | 41 | Unlike other build plugins, this plugin reads directly from your package `src/` directory. Make sure your code exists in a `src/` directory, with an `src/index.ml` or `src/index.re` file acting as your package entrypoint. 42 | 43 | Other build plugins will depend on the resulting distribution, so include this plugin early in your build pipeline for others to use. 44 | 45 | 1. Adds a modern ES2018 distribution to your built package: `dist-src/` 46 | 1. Adds an "esnext" entrypoint to your built `package.json` manifest. 47 | -------------------------------------------------------------------------------- /packages/plugin-source-bucklescript/pkg/dist-node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } 6 | 7 | var path = _interopDefault(require('path')); 8 | var fs = _interopDefault(require('fs')); 9 | var rollupBuckleScript = _interopDefault(require('rollup-plugin-bucklescript')); 10 | var rollup = require('rollup'); 11 | 12 | function validate({ 13 | cwd 14 | }) { 15 | return fs.existsSync(path.join(cwd, 'src/index.re')) || fs.existsSync(path.join(cwd, 'src/index.ml')); 16 | } 17 | function manifest(newManifest) { 18 | newManifest.es2015 = newManifest.es2015 || 'dist-src/index.js'; 19 | return newManifest; 20 | } 21 | async function build({ 22 | cwd, 23 | out, 24 | reporter 25 | }) { 26 | const writeToSrc = path.join(out, 'dist-src', 'index.js'); 27 | const isReason = fs.existsSync(path.join(cwd, 'src/index.re')); 28 | const result = await rollup.rollup({ 29 | input: isReason ? 'src/index.re' : 'src/index.ml', 30 | plugins: [rollupBuckleScript()] 31 | }); 32 | await result.write({ 33 | file: writeToSrc, 34 | format: 'esm', 35 | exports: 'named' 36 | }); 37 | reporter.created(writeToSrc, 'es2015'); 38 | } 39 | 40 | exports.build = build; 41 | exports.manifest = manifest; 42 | exports.validate = validate; 43 | //# sourceMappingURL=index.js.map 44 | -------------------------------------------------------------------------------- /packages/plugin-source-bucklescript/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import rollupBuckleScript from 'rollup-plugin-bucklescript'; 4 | import { rollup } from 'rollup'; 5 | export function validate({ cwd }) { 6 | return fs.existsSync(path.join(cwd, 'src/index.re')) || fs.existsSync(path.join(cwd, 'src/index.ml')); 7 | } 8 | export function manifest(newManifest) { 9 | newManifest.es2015 = newManifest.es2015 || 'dist-src/index.js'; 10 | return newManifest; 11 | } 12 | export async function build({ cwd, out, reporter }) { 13 | const writeToSrc = path.join(out, 'dist-src', 'index.js'); 14 | const isReason = fs.existsSync(path.join(cwd, 'src/index.re')); 15 | const result = await rollup({ 16 | input: isReason ? 'src/index.re' : 'src/index.ml', 17 | plugins: [rollupBuckleScript()], 18 | }); 19 | await result.write({ 20 | file: writeToSrc, 21 | format: 'esm', 22 | exports: 'named', 23 | }); 24 | reporter.created(writeToSrc, 'es2015'); 25 | } 26 | -------------------------------------------------------------------------------- /packages/plugin-source-bucklescript/pkg/dist-types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { BuilderOptions } from '@pika/types'; 2 | export declare function validate({ cwd }: { 3 | cwd: any; 4 | }): boolean; 5 | export declare function manifest(newManifest: any): any; 6 | export declare function build({ cwd, out, reporter }: BuilderOptions): Promise; 7 | -------------------------------------------------------------------------------- /packages/plugin-source-bucklescript/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-source-bucklescript", 3 | "description": "A @pika/pack plugin: ", 4 | "version": "0.9.2", 5 | "license": "MIT", 6 | "files": [ 7 | "dist-*/", 8 | "bin/" 9 | ], 10 | "pika": true, 11 | "sideEffects": false, 12 | "homepage": "https://www.pikapkg.com", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/pikapkg/builders.git" 16 | }, 17 | "dependencies": { 18 | "@pika/types": "^0.9.2", 19 | "rollup": "^2.3.0", 20 | "rollup-plugin-bucklescript": "^0.7.0" 21 | }, 22 | "peerDependencies": { 23 | "bs-platform": "*" 24 | }, 25 | "devDependencies": { 26 | "@pika/pack": "^0.5.0", 27 | "@pika/plugin-build-node": "^0.9.2", 28 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 29 | "@types/node": "^10.12.18", 30 | "typescript": "^3.0.0" 31 | }, 32 | "publishConfig": { 33 | "access": "public" 34 | }, 35 | "source": "dist-src/index.js", 36 | "types": "dist-types/index.d.ts", 37 | "main": "dist-node/index.js" 38 | } 39 | -------------------------------------------------------------------------------- /packages/plugin-source-bucklescript/src/index.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import rollupBuckleScript from 'rollup-plugin-bucklescript'; 4 | import {BuilderOptions} from '@pika/types'; 5 | import {rollup} from 'rollup'; 6 | 7 | export function validate({cwd}) { 8 | return fs.existsSync(path.join(cwd, 'src/index.re')) || fs.existsSync(path.join(cwd, 'src/index.ml')); 9 | } 10 | 11 | export function manifest(newManifest) { 12 | newManifest.es2015 = newManifest.es2015 || 'dist-src/index.js'; 13 | return newManifest; 14 | } 15 | 16 | export async function build({cwd, out, reporter}: BuilderOptions): Promise { 17 | const writeToSrc = path.join(out, 'dist-src', 'index.js'); 18 | const isReason = fs.existsSync(path.join(cwd, 'src/index.re')); 19 | const result = await rollup({ 20 | input: isReason ? 'src/index.re' : 'src/index.ml', 21 | plugins: [rollupBuckleScript()], 22 | }); 23 | await result.write({ 24 | file: writeToSrc, 25 | format: 'esm', 26 | exports: 'named', 27 | }); 28 | reporter.created(writeToSrc, 'es2015'); 29 | } 30 | -------------------------------------------------------------------------------- /packages/plugin-source-bucklescript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["src"], 4 | "exclude": ["node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/plugin-standard-pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-standard-pkg 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Builds your package source as standard, ES2018 JavaScript. Supports TypeScript. Supports experimental language features via Babel. 5 | 6 | > *Note: If your package is written in TypeScript, check out `@pika/plugin-ts-standard-pkg` which uses TypeScript internally to build your package instead of Babel.* 7 | 8 | 9 | 10 | ## Install 11 | 12 | ```sh 13 | # npm: 14 | npm install @pika/plugin-standard-pkg --save-dev 15 | # yarn: 16 | yarn add @pika/plugin-standard-pkg --dev 17 | ``` 18 | 19 | 20 | ## Usage 21 | 22 | ```json 23 | { 24 | "name": "example-package-json", 25 | "version": "1.0.0", 26 | "@pika/pack": { 27 | "pipeline": [ 28 | ["@pika/plugin-standard-pkg"] 29 | ] 30 | } 31 | } 32 | ``` 33 | 34 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 35 | 36 | 37 | ## Result 38 | 39 | Unlike other build plugins, this plugin reads directly from your package `src/` directory. Make sure your code exists in a `src/` directory, with an `src/index.js` or `src/index.ts` file as the package entrypoint. 40 | 41 | Other build plugins will depend on this standard ES2018 distribution, so include this plugin early in your build pipeline for others to use. 42 | 43 | 1. Adds a modern ES2018 distribution to your built package: `dist-src/` 44 | 1. TypeScript supported automatically. 45 | 1. Experimental ESNext JavaScript features are handled via your existing Babel config (`.babelrc` or similar.) 46 | 1. Adds an "esnext" entrypoint to your built `package.json` manifest. 47 | -------------------------------------------------------------------------------- /packages/plugin-standard-pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-standard-pkg", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: Builds your package source as standard, ES2018 JavaScript.", 5 | "license": "MIT", 6 | "main": "pkg/dist-node/index.js", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "@pika/plugin-ts-standard-pkg" 19 | ], 20 | [ 21 | "@pika/plugin-build-node" 22 | ] 23 | ] 24 | }, 25 | "scripts": { 26 | "build": "pika-pack build" 27 | }, 28 | "dependencies": { 29 | "@pika/types": "^0.9.2", 30 | "@types/node": "^13.13.0", 31 | "standard-pkg": "^0.5.0" 32 | }, 33 | "devDependencies": { 34 | "@pika/pack": "^0.5.0", 35 | "@pika/plugin-build-node": "^0.9.2", 36 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 37 | "typescript": "^3.0.0" 38 | }, 39 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593" 40 | } 41 | -------------------------------------------------------------------------------- /packages/plugin-standard-pkg/pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-standard-pkg 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Builds your package source as standard, ES2018 JavaScript. Supports TypeScript. Supports experimental language features via Babel. 5 | 6 | > *Note: If your package is written in TypeScript, check out `@pika/plugin-ts-standard-pkg` which uses TypeScript internally to build your package instead of Babel.* 7 | 8 | 9 | 10 | ## Install 11 | 12 | ```sh 13 | # npm: 14 | npm install @pika/plugin-standard-pkg --save-dev 15 | # yarn: 16 | yarn add @pika/plugin-standard-pkg --dev 17 | ``` 18 | 19 | 20 | ## Usage 21 | 22 | ```json 23 | { 24 | "name": "example-package-json", 25 | "version": "1.0.0", 26 | "@pika/pack": { 27 | "pipeline": [ 28 | ["@pika/plugin-standard-pkg"] 29 | ] 30 | } 31 | } 32 | ``` 33 | 34 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 35 | 36 | 37 | ## Result 38 | 39 | Unlike other build plugins, this plugin reads directly from your package `src/` directory. Make sure your code exists in a `src/` directory, with an `src/index.js` or `src/index.ts` file as the package entrypoint. 40 | 41 | Other build plugins will depend on this standard ES2018 distribution, so include this plugin early in your build pipeline for others to use. 42 | 43 | 1. Adds a modern ES2018 distribution to your built package: `dist-src/` 44 | 1. TypeScript supported automatically. 45 | 1. Experimental ESNext JavaScript features are handled via your existing Babel config (`.babelrc` or similar.) 46 | 1. Adds an "esnext" entrypoint to your built `package.json` manifest. 47 | -------------------------------------------------------------------------------- /packages/plugin-standard-pkg/pkg/dist-node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } 6 | 7 | var path = _interopDefault(require('path')); 8 | var fs = _interopDefault(require('fs')); 9 | var types = require('@pika/types'); 10 | var standardPkg = require('standard-pkg'); 11 | 12 | async function beforeJob({ 13 | cwd 14 | }) { 15 | const srcDirectory = path.join(cwd, 'src/'); 16 | 17 | if (!fs.existsSync(srcDirectory)) { 18 | throw new types.MessageError('@pika/pack expects a standard package format, where package source must live in "src/".'); 19 | } 20 | 21 | if (!fs.existsSync(path.join(cwd, 'src/index.js')) && !fs.existsSync(path.join(cwd, 'src/index.ts')) && !fs.existsSync(path.join(cwd, 'src/index.jsx')) && !fs.existsSync(path.join(cwd, 'src/index.tsx'))) { 22 | throw new types.MessageError('@pika/pack expects a standard package format, where the package entrypoint must live at "src/index".'); 23 | } 24 | } 25 | async function afterJob({ 26 | out, 27 | reporter 28 | }) { 29 | reporter.info('Linting with standard-pkg...'); 30 | const linter = new standardPkg.Lint(path.join(out, 'dist-src')); 31 | await linter.init(); 32 | linter.summary(); 33 | } 34 | function manifest(newManifest) { 35 | newManifest.esnext = newManifest.esnext || 'dist-src/index.js'; 36 | return newManifest; 37 | } 38 | async function build({ 39 | cwd, 40 | out, 41 | options, 42 | reporter 43 | }) { 44 | const builder = new standardPkg.Build(path.join(cwd, 'src'), options); 45 | await builder.init(); 46 | await builder.write(path.join(out, '/dist-src/')); 47 | reporter.created(path.join(out, 'dist-src', 'index.js'), 'esnext'); 48 | } 49 | 50 | exports.afterJob = afterJob; 51 | exports.beforeJob = beforeJob; 52 | exports.build = build; 53 | exports.manifest = manifest; 54 | //# sourceMappingURL=index.js.map 55 | -------------------------------------------------------------------------------- /packages/plugin-standard-pkg/pkg/dist-node/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sources":["../dist-src/index.js"],"sourcesContent":["import path from 'path';\nimport fs from 'fs';\nimport { MessageError } from '@pika/types';\nimport { Lint, Build } from 'standard-pkg';\nexport async function beforeJob({ cwd }) {\n const srcDirectory = path.join(cwd, 'src/');\n if (!fs.existsSync(srcDirectory)) {\n throw new MessageError('@pika/pack expects a standard package format, where package source must live in \"src/\".');\n }\n if (!fs.existsSync(path.join(cwd, 'src/index.js')) &&\n !fs.existsSync(path.join(cwd, 'src/index.ts')) &&\n !fs.existsSync(path.join(cwd, 'src/index.jsx')) &&\n !fs.existsSync(path.join(cwd, 'src/index.tsx'))) {\n throw new MessageError('@pika/pack expects a standard package format, where the package entrypoint must live at \"src/index\".');\n }\n}\nexport async function afterJob({ out, reporter }) {\n reporter.info('Linting with standard-pkg...');\n const linter = new Lint(path.join(out, 'dist-src'));\n await linter.init();\n linter.summary();\n}\nexport function manifest(newManifest) {\n newManifest.esnext = newManifest.esnext || 'dist-src/index.js';\n return newManifest;\n}\nexport async function build({ cwd, out, options, reporter }) {\n const builder = new Build(path.join(cwd, 'src'), options);\n await builder.init();\n await builder.write(path.join(out, '/dist-src/'));\n reporter.created(path.join(out, 'dist-src', 'index.js'), 'esnext');\n}\n"],"names":["beforeJob","cwd","srcDirectory","path","join","fs","existsSync","MessageError","afterJob","out","reporter","info","linter","Lint","init","summary","manifest","newManifest","esnext","build","options","builder","Build","write","created"],"mappings":";;;;;;;;;;;AAIO,eAAeA,SAAf,CAAyB;AAAEC,EAAAA;AAAF,CAAzB,EAAkC;AACrC,QAAMC,YAAY,GAAGC,IAAI,CAACC,IAAL,CAAUH,GAAV,EAAe,MAAf,CAArB;;AACA,MAAI,CAACI,EAAE,CAACC,UAAH,CAAcJ,YAAd,CAAL,EAAkC;AAC9B,UAAM,IAAIK,kBAAJ,CAAiB,yFAAjB,CAAN;AACH;;AACD,MAAI,CAACF,EAAE,CAACC,UAAH,CAAcH,IAAI,CAACC,IAAL,CAAUH,GAAV,EAAe,cAAf,CAAd,CAAD,IACA,CAACI,EAAE,CAACC,UAAH,CAAcH,IAAI,CAACC,IAAL,CAAUH,GAAV,EAAe,cAAf,CAAd,CADD,IAEA,CAACI,EAAE,CAACC,UAAH,CAAcH,IAAI,CAACC,IAAL,CAAUH,GAAV,EAAe,eAAf,CAAd,CAFD,IAGA,CAACI,EAAE,CAACC,UAAH,CAAcH,IAAI,CAACC,IAAL,CAAUH,GAAV,EAAe,eAAf,CAAd,CAHL,EAGqD;AACjD,UAAM,IAAIM,kBAAJ,CAAiB,sGAAjB,CAAN;AACH;AACJ;AACM,eAAeC,QAAf,CAAwB;AAAEC,EAAAA,GAAF;AAAOC,EAAAA;AAAP,CAAxB,EAA2C;AAC9CA,EAAAA,QAAQ,CAACC,IAAT,CAAc,8BAAd;AACA,QAAMC,MAAM,GAAG,IAAIC,gBAAJ,CAASV,IAAI,CAACC,IAAL,CAAUK,GAAV,EAAe,UAAf,CAAT,CAAf;AACA,QAAMG,MAAM,CAACE,IAAP,EAAN;AACAF,EAAAA,MAAM,CAACG,OAAP;AACH;AACM,SAASC,QAAT,CAAkBC,WAAlB,EAA+B;AAClCA,EAAAA,WAAW,CAACC,MAAZ,GAAqBD,WAAW,CAACC,MAAZ,IAAsB,mBAA3C;AACA,SAAOD,WAAP;AACH;AACM,eAAeE,KAAf,CAAqB;AAAElB,EAAAA,GAAF;AAAOQ,EAAAA,GAAP;AAAYW,EAAAA,OAAZ;AAAqBV,EAAAA;AAArB,CAArB,EAAsD;AACzD,QAAMW,OAAO,GAAG,IAAIC,iBAAJ,CAAUnB,IAAI,CAACC,IAAL,CAAUH,GAAV,EAAe,KAAf,CAAV,EAAiCmB,OAAjC,CAAhB;AACA,QAAMC,OAAO,CAACP,IAAR,EAAN;AACA,QAAMO,OAAO,CAACE,KAAR,CAAcpB,IAAI,CAACC,IAAL,CAAUK,GAAV,EAAe,YAAf,CAAd,CAAN;AACAC,EAAAA,QAAQ,CAACc,OAAT,CAAiBrB,IAAI,CAACC,IAAL,CAAUK,GAAV,EAAe,UAAf,EAA2B,UAA3B,CAAjB,EAAyD,QAAzD;AACH;;;;;;;"} -------------------------------------------------------------------------------- /packages/plugin-standard-pkg/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import { MessageError } from '@pika/types'; 4 | import { Lint, Build } from 'standard-pkg'; 5 | export async function beforeJob({ cwd }) { 6 | const srcDirectory = path.join(cwd, 'src/'); 7 | if (!fs.existsSync(srcDirectory)) { 8 | throw new MessageError('@pika/pack expects a standard package format, where package source must live in "src/".'); 9 | } 10 | if (!fs.existsSync(path.join(cwd, 'src/index.js')) && 11 | !fs.existsSync(path.join(cwd, 'src/index.ts')) && 12 | !fs.existsSync(path.join(cwd, 'src/index.jsx')) && 13 | !fs.existsSync(path.join(cwd, 'src/index.tsx'))) { 14 | throw new MessageError('@pika/pack expects a standard package format, where the package entrypoint must live at "src/index".'); 15 | } 16 | } 17 | export async function afterJob({ out, reporter }) { 18 | reporter.info('Linting with standard-pkg...'); 19 | const linter = new Lint(path.join(out, 'dist-src')); 20 | await linter.init(); 21 | linter.summary(); 22 | } 23 | export function manifest(newManifest) { 24 | newManifest.esnext = newManifest.esnext || 'dist-src/index.js'; 25 | return newManifest; 26 | } 27 | export async function build({ cwd, out, options, reporter }) { 28 | const builder = new Build(path.join(cwd, 'src'), options); 29 | await builder.init(); 30 | await builder.write(path.join(out, '/dist-src/')); 31 | reporter.created(path.join(out, 'dist-src', 'index.js'), 'esnext'); 32 | } 33 | -------------------------------------------------------------------------------- /packages/plugin-standard-pkg/pkg/dist-types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { BuilderOptions } from '@pika/types'; 2 | export declare function beforeJob({ cwd }: BuilderOptions): Promise; 3 | export declare function afterJob({ out, reporter }: BuilderOptions): Promise; 4 | export declare function manifest(newManifest: any): any; 5 | export declare function build({ cwd, out, options, reporter }: BuilderOptions): Promise; 6 | -------------------------------------------------------------------------------- /packages/plugin-standard-pkg/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-standard-pkg", 3 | "description": "A @pika/pack plugin: Builds your package source as standard, ES2018 JavaScript.", 4 | "version": "0.9.2", 5 | "license": "MIT", 6 | "files": [ 7 | "dist-*/", 8 | "bin/" 9 | ], 10 | "pika": true, 11 | "sideEffects": false, 12 | "homepage": "https://www.pikapkg.com", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/pikapkg/builders.git" 16 | }, 17 | "dependencies": { 18 | "@pika/types": "^0.9.2", 19 | "@types/node": "^10.12.18", 20 | "standard-pkg": "^0.5.0" 21 | }, 22 | "devDependencies": { 23 | "@pika/pack": "^0.5.0", 24 | "@pika/plugin-build-node": "^0.9.2", 25 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 26 | "typescript": "^3.0.0" 27 | }, 28 | "publishConfig": { 29 | "access": "public" 30 | }, 31 | "source": "dist-src/index.js", 32 | "types": "dist-types/index.d.ts", 33 | "main": "dist-node/index.js" 34 | } 35 | -------------------------------------------------------------------------------- /packages/plugin-standard-pkg/src/index.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import {BuilderOptions, MessageError} from '@pika/types'; 4 | import {Lint, Build} from 'standard-pkg'; 5 | 6 | export async function beforeJob({cwd}: BuilderOptions) { 7 | const srcDirectory = path.join(cwd, 'src/'); 8 | if (!fs.existsSync(srcDirectory)) { 9 | throw new MessageError('@pika/pack expects a standard package format, where package source must live in "src/".'); 10 | } 11 | if ( 12 | !fs.existsSync(path.join(cwd, 'src/index.js')) && 13 | !fs.existsSync(path.join(cwd, 'src/index.ts')) && 14 | !fs.existsSync(path.join(cwd, 'src/index.jsx')) && 15 | !fs.existsSync(path.join(cwd, 'src/index.tsx')) 16 | ) { 17 | throw new MessageError( 18 | '@pika/pack expects a standard package format, where the package entrypoint must live at "src/index".', 19 | ); 20 | } 21 | } 22 | 23 | export async function afterJob({out, reporter}: BuilderOptions) { 24 | reporter.info('Linting with standard-pkg...'); 25 | const linter = new Lint(path.join(out, 'dist-src')); 26 | await linter.init(); 27 | linter.summary(); 28 | } 29 | 30 | export function manifest(newManifest) { 31 | newManifest.esnext = newManifest.esnext || 'dist-src/index.js'; 32 | return newManifest; 33 | } 34 | 35 | export async function build({cwd, out, options, reporter}: BuilderOptions): Promise { 36 | const builder = new Build(path.join(cwd, 'src'), options); 37 | await builder.init(); 38 | await builder.write(path.join(out, '/dist-src/')); 39 | reporter.created(path.join(out, 'dist-src', 'index.js'), 'esnext'); 40 | } 41 | -------------------------------------------------------------------------------- /packages/plugin-standard-pkg/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["src"], 4 | "exclude": ["node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/plugin-transform-imports/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-transform-imports 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > rewrite imports, if you need that sort of thing. 5 | 6 | > *Note: This is an advanced plugin that 99.99% of people won't need.* 7 | 8 | 9 | ## Install 10 | 11 | ```sh 12 | # npm: 13 | npm install @pika/plugin-transform-imports --save-dev 14 | # yarn: 15 | yarn add @pika/plugin-transform-imports --dev 16 | ``` 17 | 18 | 19 | ## Usage 20 | 21 | ```js 22 | { 23 | "name": "example-package-json", 24 | "version": "1.0.0", 25 | "@pika/pack": { 26 | "pipeline": [ 27 | ["@pika/plugin-ts-standard-pkg"], 28 | ["@pika/plugin-transform-imports", { /* options: see below */ }], 29 | /* your other build plugins */ 30 | ] 31 | } 32 | } 33 | ``` 34 | 35 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 36 | 37 | 38 | ## Options 39 | 40 | - `"rewrite"`: An object map of imports to rewrite in some of the dist directories. -------------------------------------------------------------------------------- /packages/plugin-transform-imports/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-transform-imports", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: rewrite imports, if you need that sort of thing.", 5 | "license": "MIT", 6 | "main": "pkg/dist-node/index.js", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "@pika/plugin-ts-standard-pkg" 19 | ], 20 | [ 21 | "@pika/plugin-build-node" 22 | ] 23 | ] 24 | }, 25 | "scripts": { 26 | "build": "pika-pack build" 27 | }, 28 | "dependencies": { 29 | "@pika/types": "^0.9.2", 30 | "@types/node": "^10.12.18" 31 | }, 32 | "devDependencies": { 33 | "@pika/pack": "^0.5.0", 34 | "@pika/plugin-build-node": "^0.9.2", 35 | "@pika/plugin-ts-standard-pkg": "^0.9.2", 36 | "typescript": "^3.0.0" 37 | }, 38 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593" 39 | } 40 | -------------------------------------------------------------------------------- /packages/plugin-transform-imports/src/index.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import {promises as fs} from 'fs'; 3 | import {BuilderOptions, MessageError} from '@pika/types'; 4 | const ESM_IMPORT = /import(?:["'\s]*([\w*${}\n\r\t, ]+)from\s*)?["'\s]["'\s](@?[\w-]+[:\/]?[\w-]+)["'\s].*;$/gm; 5 | 6 | async function getAllFiles(dir) { 7 | let dirents; 8 | try { 9 | dirents = await fs.readdir(dir, {withFileTypes: true}); 10 | } catch (err) { 11 | if (err.code === 'ENOENT') { 12 | return []; 13 | } 14 | throw err; 15 | } 16 | const files = await Promise.all( 17 | dirents.map(dirent => { 18 | const res = path.resolve(dir, dirent.name); 19 | return dirent.isDirectory() ? getAllFiles(res) : res; 20 | }), 21 | ); 22 | return Array.prototype.concat(...files); 23 | } 24 | 25 | export async function build({out, options, reporter}: BuilderOptions): Promise { 26 | const rewriteMap = options.rewrite || {}; 27 | const [allSrcFilePaths, allTypesFilePaths] = await Promise.all([ 28 | getAllFiles(path.join(out, 'dist-src/')), 29 | getAllFiles(path.join(out, 'dist-types/')), 30 | ]); 31 | 32 | for (const filePath of [...allSrcFilePaths, ...allTypesFilePaths]) { 33 | const fileContents = await fs.readFile(filePath, {encoding: 'utf8'}); 34 | const newFileContents = fileContents.replace(ESM_IMPORT, (full, imp, spec) => { 35 | const rewrittenSpec = rewriteMap[spec]; 36 | if (!rewrittenSpec) { 37 | throw new MessageError('Unexpected import: ' + spec); 38 | } 39 | return `import ${imp} from '${rewrittenSpec}';`; 40 | }); 41 | await fs.writeFile(filePath, newFileContents, {encoding: 'utf8'}); 42 | } 43 | 44 | reporter.info('rewritten'); 45 | } 46 | -------------------------------------------------------------------------------- /packages/plugin-transform-imports/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["src"], 4 | "exclude": ["node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/plugin-ts-standard-pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-ts-standard-pkg 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Builds your TypeScript package source as standard, ES2018 JavaScript. Also includes type definition files for your package automatically. 5 | 6 | > *Note: If your package isn't written in TypeScript, check out the normal `@pika/plugin-standard-pkg` plugin.* 7 | 8 | 9 | ## Install 10 | 11 | ```sh 12 | # npm: 13 | npm install @pika/plugin-ts-standard-pkg --save-dev 14 | # yarn: 15 | yarn add @pika/plugin-ts-standard-pkg --dev 16 | ``` 17 | 18 | 19 | ## Usage 20 | 21 | ```js 22 | { 23 | "name": "example-package-json", 24 | "version": "1.0.0", 25 | "@pika/pack": { 26 | "pipeline": [ 27 | ["@pika/plugin-ts-standard-pkg", { /* options: see below */ }] 28 | ] 29 | } 30 | } 31 | ``` 32 | 33 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 34 | 35 | 36 | ## Options 37 | 38 | This plugin runs `tsc` internally, so it supports all [tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) options defined in your project-level config file (like `compilerOptions` & `exclude`). 39 | 40 | - `"tsconfig"`: Optional, the relative path to the `tsconfig.json` config file to use. Defaults to the top-level project TypeScript config file, if one exists. 41 | - `"args"`: Optional, an array of additional arguments for tsc. Example: `["--build"]` 42 | 43 | 44 | ## Result 45 | 46 | Unlike other build plugins, this plugin reads directly from your package `src/` directory. Make sure your code exists in a `src/` directory, with an `src/index.ts` file as the package entrypoint. 47 | 48 | Other build plugins depend on a standard ES2018 distribution, so include this plugin early in your build pipeline for others to use. 49 | 50 | 1. Adds a modern ES2018 distribution to your built package: `dist-src/` 51 | 1. Adds type definitions to your package automatically: `dist-types/` 52 | 1. Adds an "esnext" entrypoint to your built `package.json` manifest. 53 | 1. Adds a "types" entrypoint to your built `package.json` manifest. 54 | -------------------------------------------------------------------------------- /packages/plugin-ts-standard-pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-ts-standard-pkg", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: Builds your TypeScript package source as standard, ES2018 JavaScript.", 5 | "license": "MIT", 6 | "main": "pkg/dist-node/index.js", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "./pkg" 19 | ], 20 | [ 21 | "@pika/plugin-build-node" 22 | ] 23 | ] 24 | }, 25 | "scripts": { 26 | "build": "pika-pack build" 27 | }, 28 | "dependencies": { 29 | "@pika/types": "^0.9.2", 30 | "execa": "^2.0.0", 31 | "standard-pkg": "^0.5.0" 32 | }, 33 | "devDependencies": { 34 | "@pika/pack": "^0.5.0", 35 | "@pika/plugin-build-node": "^0.9.2", 36 | "@types/node": "^10.12.18", 37 | "typescript": "^3.0.0" 38 | }, 39 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593" 40 | } 41 | -------------------------------------------------------------------------------- /packages/plugin-ts-standard-pkg/pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-ts-standard-pkg 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Builds your TypeScript package source as standard, ES2018 JavaScript. Also includes type definition files for your package automatically. 5 | 6 | > *Note: If your package isn't written in TypeScript, check out the normal `@pika/plugin-standard-pkg` plugin.* 7 | 8 | 9 | ## Install 10 | 11 | ```sh 12 | # npm: 13 | npm install @pika/plugin-ts-standard-pkg --save-dev 14 | # yarn: 15 | yarn add @pika/plugin-ts-standard-pkg --dev 16 | ``` 17 | 18 | 19 | ## Usage 20 | 21 | ```js 22 | { 23 | "name": "example-package-json", 24 | "version": "1.0.0", 25 | "@pika/pack": { 26 | "pipeline": [ 27 | ["@pika/plugin-ts-standard-pkg", { /* options: see below */ }] 28 | ] 29 | } 30 | } 31 | ``` 32 | 33 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 34 | 35 | 36 | ## Options 37 | 38 | This plugin runs `tsc` internally, so it supports all [tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) options defined in your project-level config file (like `compilerOptions` & `exclude`). 39 | 40 | - `"tsconfig"`: Optional, the relative path to the `tsconfig.json` config file to use. Defaults to the top-level project TypeScript config file, if one exists. 41 | - `"args"`: Optional, an array of additional arguments for tsc. Example: `["--build"]` 42 | 43 | 44 | ## Result 45 | 46 | Unlike other build plugins, this plugin reads directly from your package `src/` directory. Make sure your code exists in a `src/` directory, with an `src/index.ts` file as the package entrypoint. 47 | 48 | Other build plugins depend on a standard ES2018 distribution, so include this plugin early in your build pipeline for others to use. 49 | 50 | 1. Adds a modern ES2018 distribution to your built package: `dist-src/` 51 | 1. Adds type definitions to your package automatically: `dist-types/` 52 | 1. Adds an "esnext" entrypoint to your built `package.json` manifest. 53 | 1. Adds a "types" entrypoint to your built `package.json` manifest. 54 | -------------------------------------------------------------------------------- /packages/plugin-ts-standard-pkg/pkg/dist-types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { BuilderOptions } from '@pika/types'; 2 | export declare function beforeBuild({ cwd, options, reporter }: BuilderOptions): Promise; 3 | export declare function beforeJob({ cwd }: BuilderOptions): Promise; 4 | export declare function afterJob({ out, reporter }: BuilderOptions): Promise; 5 | export declare function manifest(newManifest: any): any; 6 | export declare function build({ cwd, out, options, reporter }: BuilderOptions): Promise; 7 | -------------------------------------------------------------------------------- /packages/plugin-ts-standard-pkg/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-ts-standard-pkg", 3 | "description": "A @pika/pack plugin: Builds your TypeScript package source as standard, ES2018 JavaScript.", 4 | "version": "0.9.2", 5 | "license": "MIT", 6 | "files": [ 7 | "dist-*/", 8 | "bin/" 9 | ], 10 | "pika": true, 11 | "sideEffects": false, 12 | "homepage": "https://www.pikapkg.com", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/pikapkg/builders.git" 16 | }, 17 | "dependencies": { 18 | "@pika/types": "^0.9.2", 19 | "execa": "^2.0.0", 20 | "standard-pkg": "^0.5.0" 21 | }, 22 | "devDependencies": { 23 | "@pika/pack": "^0.5.0", 24 | "@pika/plugin-build-node": "^0.9.2", 25 | "@types/node": "^10.12.18", 26 | "typescript": "^3.0.0" 27 | }, 28 | "publishConfig": { 29 | "access": "public" 30 | }, 31 | "source": "dist-src/index.js", 32 | "types": "dist-types/index.d.ts", 33 | "main": "dist-node/index.js" 34 | } 35 | -------------------------------------------------------------------------------- /packages/plugin-ts-standard-pkg/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["src"], 4 | "exclude": ["node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/plugin-wasm-assemblyscript/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-wasm-assemblyscript 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Builds TypeScript as WASM via AssemblyScript. 5 | 6 | 7 | 8 | 9 | ## Install 10 | 11 | ```sh 12 | # npm: 13 | npm install @pika/plugin-wasm-assemblyscript --save-dev 14 | # yarn: 15 | yarn add @pika/plugin-wasm-assemblyscript --dev 16 | ``` 17 | 18 | 19 | ## Usage 20 | 21 | ```json 22 | { 23 | "name": "example-package-json", 24 | "version": "1.0.0", 25 | "@pika/pack": { 26 | "pipeline": [ 27 | ["@pika/plugin-wasm-assemblyscript"], 28 | ["@pika/plugin-wasm-bindings"], 29 | ["@pika/plugin-build-web"] 30 | ] 31 | } 32 | } 33 | ``` 34 | 35 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 36 | 37 | 38 | ## Result 39 | 40 | Unlike other build plugins, this plugin reads directly from your package `src/` directory. Make sure your code exists in a `src/` directory, with an `index.ts` file as the package entrypoint. 41 | 42 | 1. Compiles your TypeScript to WASM: `assets/index.wasm` 43 | 44 | Note that this plugin is only responsible for building the WASM asset. Be sure to include JavaScript bindings so that your package can be loaded like any other JavaScript module. -------------------------------------------------------------------------------- /packages/plugin-wasm-assemblyscript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-wasm-assemblyscript", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: Builds TypeScript as WASM via AssemblyScript.", 5 | "main": "pkg/dist-node/index.js", 6 | "license": "MIT", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "@pika/plugin-standard-pkg" 19 | ], 20 | [ 21 | "@pika/plugin-build-node" 22 | ] 23 | ] 24 | }, 25 | "scripts": { 26 | "build": "pika-pack build" 27 | }, 28 | "dependencies": { 29 | "assemblyscript": "github:AssemblyScript/assemblyscript" 30 | }, 31 | "devDependencies": { 32 | "@pika/pack": "^0.5.0", 33 | "@pika/plugin-build-node": "^0.9.2", 34 | "@pika/plugin-standard-pkg": "^0.9.2", 35 | "@types/node": "^10.12.18" 36 | }, 37 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593" 38 | } 39 | -------------------------------------------------------------------------------- /packages/plugin-wasm-assemblyscript/pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-wasm-assemblyscript 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Builds TypeScript as WASM via AssemblyScript. 5 | 6 | 7 | 8 | 9 | ## Install 10 | 11 | ```sh 12 | # npm: 13 | npm install @pika/plugin-wasm-assemblyscript --save-dev 14 | # yarn: 15 | yarn add @pika/plugin-wasm-assemblyscript --dev 16 | ``` 17 | 18 | 19 | ## Usage 20 | 21 | ```json 22 | { 23 | "name": "example-package-json", 24 | "version": "1.0.0", 25 | "@pika/pack": { 26 | "pipeline": [ 27 | ["@pika/plugin-wasm-assemblyscript"], 28 | ["@pika/plugin-wasm-bindings"], 29 | ["@pika/plugin-build-web"] 30 | ] 31 | } 32 | } 33 | ``` 34 | 35 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 36 | 37 | 38 | ## Result 39 | 40 | Unlike other build plugins, this plugin reads directly from your package `src/` directory. Make sure your code exists in a `src/` directory, with an `index.ts` file as the package entrypoint. 41 | 42 | 1. Compiles your TypeScript to WASM: `assets/index.wasm` 43 | 44 | Note that this plugin is only responsible for building the WASM asset. Be sure to include JavaScript bindings so that your package can be loaded like any other JavaScript module. -------------------------------------------------------------------------------- /packages/plugin-wasm-assemblyscript/pkg/dist-node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } 6 | 7 | var path = _interopDefault(require('path')); 8 | var fs = _interopDefault(require('fs')); 9 | var asc = _interopDefault(require('assemblyscript/cli/asc')); 10 | 11 | function validate({ 12 | cwd 13 | }) { 14 | return fs.existsSync(path.join(cwd, "src/index.ts")); 15 | } 16 | function manifest(newManifest) { 17 | return newManifest; 18 | } 19 | async function build({ 20 | out, 21 | cwd, 22 | options, 23 | reporter 24 | }) { 25 | const relativeOutWasm = path.relative(cwd, path.join(out, "assets/index.wasm")); 26 | const relativeOutTypes = path.relative(cwd, path.join(out, "assets/index.d.ts")); 27 | await new Promise((resolve, reject) => { 28 | asc.main(["src/index.ts", "--binaryFile", relativeOutWasm, "-d", relativeOutTypes, "--optimize", "--sourceMap", // Optional: 29 | "--use", " Math=JSMath", "-O3", "--importMemory", ...(options.args || [])], { 30 | stdout: reporter.stdout, 31 | stderr: reporter.stderr 32 | }, err => { 33 | if (err) { 34 | reject(err); 35 | return; 36 | } 37 | 38 | resolve(); 39 | }); 40 | }); 41 | reporter.created(path.join(out, "assets/index.wasm")); 42 | } 43 | 44 | exports.build = build; 45 | exports.manifest = manifest; 46 | exports.validate = validate; 47 | //# sourceMappingURL=index.js.map 48 | -------------------------------------------------------------------------------- /packages/plugin-wasm-assemblyscript/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import fs from "fs"; 3 | import asc from "assemblyscript/cli/asc"; 4 | export function validate({ 5 | cwd 6 | }) { 7 | return fs.existsSync(path.join(cwd, "src/index.ts")); 8 | } 9 | export function manifest(newManifest) { 10 | return newManifest; 11 | } 12 | export async function build({ 13 | out, 14 | cwd, 15 | options, 16 | reporter 17 | }) { 18 | const relativeOutWasm = path.relative(cwd, path.join(out, "assets/index.wasm")); 19 | const relativeOutTypes = path.relative(cwd, path.join(out, "assets/index.d.ts")); 20 | await new Promise((resolve, reject) => { 21 | asc.main(["src/index.ts", "--binaryFile", relativeOutWasm, "-d", relativeOutTypes, "--optimize", "--sourceMap", // Optional: 22 | "--use", " Math=JSMath", "-O3", "--importMemory", ...(options.args || [])], { 23 | stdout: reporter.stdout, 24 | stderr: reporter.stderr 25 | }, err => { 26 | if (err) { 27 | reject(err); 28 | return; 29 | } 30 | 31 | resolve(); 32 | }); 33 | }); 34 | reporter.created(path.join(out, "assets/index.wasm")); 35 | } -------------------------------------------------------------------------------- /packages/plugin-wasm-assemblyscript/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-wasm-assemblyscript", 3 | "description": "A @pika/pack plugin: Builds TypeScript as WASM via AssemblyScript.", 4 | "version": "0.9.2", 5 | "license": "MIT", 6 | "files": [ 7 | "dist-*/", 8 | "bin/" 9 | ], 10 | "pika": true, 11 | "sideEffects": false, 12 | "homepage": "https://www.pikapkg.com", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/pikapkg/builders.git" 16 | }, 17 | "dependencies": { 18 | "assemblyscript": "github:AssemblyScript/assemblyscript" 19 | }, 20 | "devDependencies": { 21 | "@pika/pack": "^0.5.0", 22 | "@pika/plugin-build-node": "^0.9.2", 23 | "@pika/plugin-standard-pkg": "^0.9.2", 24 | "@types/node": "^10.12.18" 25 | }, 26 | "publishConfig": { 27 | "access": "public" 28 | }, 29 | "esnext": "dist-src/index.js", 30 | "main": "dist-node/index.js" 31 | } 32 | -------------------------------------------------------------------------------- /packages/plugin-wasm-assemblyscript/src/index.js: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import fs from "fs"; 3 | import asc from "assemblyscript/cli/asc"; 4 | 5 | export function validate({ cwd }) { 6 | return fs.existsSync(path.join(cwd, "src/index.ts")); 7 | } 8 | 9 | export function manifest(newManifest) { 10 | return newManifest; 11 | } 12 | 13 | export async function build({ out, cwd, options, reporter }) { 14 | const relativeOutWasm = path.relative( 15 | cwd, 16 | path.join(out, "assets/index.wasm") 17 | ); 18 | const relativeOutTypes = path.relative( 19 | cwd, 20 | path.join(out, "assets/index.d.ts") 21 | ); 22 | await new Promise((resolve, reject) => { 23 | asc.main( 24 | [ 25 | "src/index.ts", 26 | "--binaryFile", 27 | relativeOutWasm, 28 | "-d", 29 | relativeOutTypes, 30 | "--optimize", 31 | "--sourceMap", 32 | // Optional: 33 | "--use", 34 | " Math=JSMath", 35 | "-O3", 36 | "--importMemory", 37 | ...(options.args || []) 38 | ], 39 | { 40 | stdout: reporter.stdout, 41 | stderr: reporter.stderr 42 | }, 43 | err => { 44 | if (err) { 45 | reject(err); 46 | return; 47 | } 48 | resolve(); 49 | } 50 | ); 51 | }); 52 | reporter.created(path.join(out, "assets/index.wasm")); 53 | } 54 | -------------------------------------------------------------------------------- /packages/plugin-wasm-assemblyscript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["src"], 4 | "exclude": ["node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/plugin-wasm-bindings/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-wasm-bindings 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds simple JavaScript bindings that work with any WASM file. 5 | 6 | 7 | 8 | 9 | ## Install 10 | 11 | ```sh 12 | # npm: 13 | npm install @pika/plugin-wasm-bindings --save-dev 14 | # yarn: 15 | yarn add @pika/plugin-wasm-bindings --dev 16 | ``` 17 | 18 | 19 | ## Usage 20 | 21 | ```json 22 | { 23 | "name": "example-package-json", 24 | "version": "1.0.0", 25 | "@pika/pack": { 26 | "pipeline": [ 27 | ["@pika/plugin-wasm-assemblyscript"], 28 | ["@pika/plugin-wasm-bindings"], 29 | ["@pika/plugin-build-web"] 30 | ] 31 | } 32 | } 33 | ``` 34 | 35 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 36 | 37 | 38 | ## Result 39 | 40 | 1. Adds ES2018 JavaScript bindings to your package: `dist-src/index.js` 41 | 1. Adds an "esnext" entrypoint to your built `package.json` manifest. 42 | 43 | Note that this plugin is only responsible for building the WASM bindings. Be sure to include a plugin that compiles the relevant WASM asset. -------------------------------------------------------------------------------- /packages/plugin-wasm-bindings/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-wasm-bindings", 3 | "version": "0.9.2", 4 | "description": "A @pika/pack plugin: adds simple JavaScript bindings that work with any WASM file.", 5 | "license": "MIT", 6 | "main": "pkg/dist-node/index.js", 7 | "homepage": "https://www.pikapkg.com", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/pikapkg/builders.git" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "@pika/pack": { 16 | "pipeline": [ 17 | [ 18 | "@pika/plugin-standard-pkg" 19 | ], 20 | [ 21 | "@pika/plugin-build-node" 22 | ] 23 | ] 24 | }, 25 | "scripts": { 26 | "build": "pika-pack build" 27 | }, 28 | "dependencies": { 29 | "mkdirp": "^0.5.0" 30 | }, 31 | "devDependencies": { 32 | "@pika/pack": "^0.5.0", 33 | "@pika/plugin-build-node": "^0.9.2", 34 | "@pika/plugin-standard-pkg": "^0.9.2", 35 | "@types/node": "^10.12.18" 36 | }, 37 | "gitHead": "88aa979a8caee0ea92510ef2f1006fcc2fdd8593" 38 | } 39 | -------------------------------------------------------------------------------- /packages/plugin-wasm-bindings/pkg/README.md: -------------------------------------------------------------------------------- 1 | # @pika/plugin-wasm-bindings 2 | 3 | > A [@pika/pack](https://github.com/pikapkg/pack) build plugin. 4 | > Adds simple JavaScript bindings that work with any WASM file. 5 | 6 | 7 | 8 | 9 | ## Install 10 | 11 | ```sh 12 | # npm: 13 | npm install @pika/plugin-wasm-bindings --save-dev 14 | # yarn: 15 | yarn add @pika/plugin-wasm-bindings --dev 16 | ``` 17 | 18 | 19 | ## Usage 20 | 21 | ```json 22 | { 23 | "name": "example-package-json", 24 | "version": "1.0.0", 25 | "@pika/pack": { 26 | "pipeline": [ 27 | ["@pika/plugin-wasm-assemblyscript"], 28 | ["@pika/plugin-wasm-bindings"], 29 | ["@pika/plugin-build-web"] 30 | ] 31 | } 32 | } 33 | ``` 34 | 35 | For more information about @pika/pack & help getting started, [check out the main project repo](https://github.com/pikapkg/pack). 36 | 37 | 38 | ## Result 39 | 40 | 1. Adds ES2018 JavaScript bindings to your package: `dist-src/index.js` 41 | 1. Adds an "esnext" entrypoint to your built `package.json` manifest. 42 | 43 | Note that this plugin is only responsible for building the WASM bindings. Be sure to include a plugin that compiles the relevant WASM asset. -------------------------------------------------------------------------------- /packages/plugin-wasm-bindings/pkg/dist-node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } 6 | 7 | var path = _interopDefault(require('path')); 8 | var fs = _interopDefault(require('fs')); 9 | var mkdirp = _interopDefault(require('mkdirp')); 10 | 11 | const SRC_WRAPPER = `export function createWASM(deps = {}) { 12 | const url = new URL("../assets/index.wasm", import.meta.url); 13 | const input = window.fetch(url); 14 | return WebAssembly.instantiateStreaming(input, deps); 15 | } 16 | export default createWASM; 17 | `; 18 | const WEB_WRAPPER = `export function createWASM(deps = {}) { 19 | if (typeof __webpack_require__ !== "undefined") { 20 | return __webpack_require__("../assets/index.wasm"); 21 | } 22 | const url = new URL("../assets/index.wasm", import.meta.url); 23 | const input = window.fetch(url); 24 | return WebAssembly.instantiateStreaming(input, deps); 25 | } 26 | export default createWASM; 27 | `; 28 | const NODE_WRAPPER = `const fs = require('fs'); 29 | const path = require('path'); 30 | exports.default = exports.createWASM = function createWASM(deps = {}) { 31 | const buf = fs.readFileSync(path.join(__dirname, '../assets/index.wasm')); 32 | return WebAssembly.instantiate(buf, deps); 33 | } 34 | `; 35 | const TYPE_DEF = `declare class WASMInstance { 36 | readonly exports: any; 37 | constructor(module: any, importObject?: any); 38 | } 39 | interface ResultObject {module: any; instance: WASMInstance} 40 | export function createWASM(importObject?: object): Promise; 41 | export default function createWASM(importObject?: object): Promise; 42 | `; 43 | function validate({ 44 | cwd 45 | }) { 46 | return true; 47 | } 48 | function manifest(newManifest) { 49 | newManifest["src"] = "dist-src/index.js"; 50 | newManifest["web"] = "dist-web/index.js"; 51 | newManifest["node"] = "dist-node/index.js"; 52 | newManifest["types"] = "dist-types/index.js"; 53 | return newManifest; 54 | } 55 | async function build({ 56 | out, 57 | reporter 58 | }) { 59 | mkdirp.sync(path.join(out, "dist-src")); 60 | fs.writeFileSync(path.join(out, "dist-src/index.js"), SRC_WRAPPER, "utf8"); 61 | reporter.created(path.join(out, "dist-src/index.js"), 'esnext'); 62 | mkdirp.sync(path.join(out, "dist-web")); 63 | fs.writeFileSync(path.join(out, "dist-web/index.js"), WEB_WRAPPER, "utf8"); 64 | reporter.created(path.join(out, "dist-web/index.js"), 'module'); 65 | mkdirp.sync(path.join(out, "dist-node")); 66 | fs.writeFileSync(path.join(out, "dist-node/index.js"), NODE_WRAPPER, "utf8"); 67 | reporter.created(path.join(out, "dist-node/index.js"), 'main'); 68 | mkdirp.sync(path.join(out, "dist-types")); 69 | fs.writeFileSync(path.join(out, "dist-types/index.d.ts"), TYPE_DEF, "utf8"); 70 | reporter.created(path.join(out, "dist-types/index.d.ts"), 'types'); 71 | } 72 | 73 | exports.build = build; 74 | exports.manifest = manifest; 75 | exports.validate = validate; 76 | //# sourceMappingURL=index.js.map 77 | -------------------------------------------------------------------------------- /packages/plugin-wasm-bindings/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import fs from "fs"; 3 | import mkdirp from "mkdirp"; 4 | const SRC_WRAPPER = `export function createWASM(deps = {}) { 5 | const url = new URL("../assets/index.wasm", import.meta.url); 6 | const input = window.fetch(url); 7 | return WebAssembly.instantiateStreaming(input, deps); 8 | } 9 | export default createWASM; 10 | `; 11 | const WEB_WRAPPER = `export function createWASM(deps = {}) { 12 | if (typeof __webpack_require__ !== "undefined") { 13 | return __webpack_require__("../assets/index.wasm"); 14 | } 15 | const url = new URL("../assets/index.wasm", import.meta.url); 16 | const input = window.fetch(url); 17 | return WebAssembly.instantiateStreaming(input, deps); 18 | } 19 | export default createWASM; 20 | `; 21 | const NODE_WRAPPER = `const fs = require('fs'); 22 | const path = require('path'); 23 | exports.default = exports.createWASM = function createWASM(deps = {}) { 24 | const buf = fs.readFileSync(path.join(__dirname, '../assets/index.wasm')); 25 | return WebAssembly.instantiate(buf, deps); 26 | } 27 | `; 28 | const TYPE_DEF = `declare class WASMInstance { 29 | readonly exports: any; 30 | constructor(module: any, importObject?: any); 31 | } 32 | interface ResultObject {module: any; instance: WASMInstance} 33 | export function createWASM(importObject?: object): Promise; 34 | export default function createWASM(importObject?: object): Promise; 35 | `; 36 | export function validate({ 37 | cwd 38 | }) { 39 | return true; 40 | } 41 | export function manifest(newManifest) { 42 | newManifest["src"] = "dist-src/index.js"; 43 | newManifest["web"] = "dist-web/index.js"; 44 | newManifest["node"] = "dist-node/index.js"; 45 | newManifest["types"] = "dist-types/index.js"; 46 | return newManifest; 47 | } 48 | export async function build({ 49 | out, 50 | reporter 51 | }) { 52 | mkdirp.sync(path.join(out, "dist-src")); 53 | fs.writeFileSync(path.join(out, "dist-src/index.js"), SRC_WRAPPER, "utf8"); 54 | reporter.created(path.join(out, "dist-src/index.js"), 'esnext'); 55 | mkdirp.sync(path.join(out, "dist-web")); 56 | fs.writeFileSync(path.join(out, "dist-web/index.js"), WEB_WRAPPER, "utf8"); 57 | reporter.created(path.join(out, "dist-web/index.js"), 'module'); 58 | mkdirp.sync(path.join(out, "dist-node")); 59 | fs.writeFileSync(path.join(out, "dist-node/index.js"), NODE_WRAPPER, "utf8"); 60 | reporter.created(path.join(out, "dist-node/index.js"), 'main'); 61 | mkdirp.sync(path.join(out, "dist-types")); 62 | fs.writeFileSync(path.join(out, "dist-types/index.d.ts"), TYPE_DEF, "utf8"); 63 | reporter.created(path.join(out, "dist-types/index.d.ts"), 'types'); 64 | } -------------------------------------------------------------------------------- /packages/plugin-wasm-bindings/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/plugin-wasm-bindings", 3 | "description": "A @pika/pack plugin: adds simple JavaScript bindings that work with any WASM file.", 4 | "version": "0.9.2", 5 | "license": "MIT", 6 | "files": [ 7 | "dist-*/", 8 | "bin/" 9 | ], 10 | "pika": true, 11 | "sideEffects": false, 12 | "homepage": "https://www.pikapkg.com", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/pikapkg/builders.git" 16 | }, 17 | "dependencies": { 18 | "mkdirp": "^0.5.0" 19 | }, 20 | "devDependencies": { 21 | "@pika/pack": "^0.5.0", 22 | "@pika/plugin-build-node": "^0.9.2", 23 | "@pika/plugin-standard-pkg": "^0.9.2", 24 | "@types/node": "^10.12.18" 25 | }, 26 | "publishConfig": { 27 | "access": "public" 28 | }, 29 | "esnext": "dist-src/index.js", 30 | "main": "dist-node/index.js" 31 | } 32 | -------------------------------------------------------------------------------- /packages/plugin-wasm-bindings/src/index.js: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import fs from "fs"; 3 | import mkdirp from "mkdirp"; 4 | 5 | const SRC_WRAPPER = `export function createWASM(deps = {}) { 6 | const url = new URL("../assets/index.wasm", import.meta.url); 7 | const input = window.fetch(url); 8 | return WebAssembly.instantiateStreaming(input, deps); 9 | } 10 | export default createWASM; 11 | `; 12 | 13 | const WEB_WRAPPER = `export function createWASM(deps = {}) { 14 | if (typeof __webpack_require__ !== "undefined") { 15 | return __webpack_require__("../assets/index.wasm"); 16 | } 17 | const url = new URL("../assets/index.wasm", import.meta.url); 18 | const input = window.fetch(url); 19 | return WebAssembly.instantiateStreaming(input, deps); 20 | } 21 | export default createWASM; 22 | `; 23 | 24 | const NODE_WRAPPER = `const fs = require('fs'); 25 | const path = require('path'); 26 | exports.default = exports.createWASM = function createWASM(deps = {}) { 27 | const buf = fs.readFileSync(path.join(__dirname, '../assets/index.wasm')); 28 | return WebAssembly.instantiate(buf, deps); 29 | } 30 | `; 31 | 32 | const TYPE_DEF = `declare class WASMInstance { 33 | readonly exports: any; 34 | constructor(module: any, importObject?: any); 35 | } 36 | interface ResultObject {module: any; instance: WASMInstance} 37 | export function createWASM(importObject?: object): Promise; 38 | export default function createWASM(importObject?: object): Promise; 39 | `; 40 | 41 | export function validate({ cwd }) { 42 | return true; 43 | } 44 | 45 | export function manifest(newManifest) { 46 | newManifest["src"] = "dist-src/index.js"; 47 | newManifest["web"] = "dist-web/index.js"; 48 | newManifest["node"] = "dist-node/index.js"; 49 | newManifest["types"] = "dist-types/index.js"; 50 | return newManifest; 51 | } 52 | 53 | export async function build({ out, reporter }) { 54 | mkdirp.sync(path.join(out, "dist-src")); 55 | fs.writeFileSync(path.join(out, "dist-src/index.js"), SRC_WRAPPER, "utf8"); 56 | reporter.created(path.join(out, "dist-src/index.js"), 'esnext'); 57 | 58 | mkdirp.sync(path.join(out, "dist-web")); 59 | fs.writeFileSync(path.join(out, "dist-web/index.js"), WEB_WRAPPER, "utf8"); 60 | reporter.created(path.join(out, "dist-web/index.js"), 'module'); 61 | 62 | mkdirp.sync(path.join(out, "dist-node")); 63 | fs.writeFileSync(path.join(out, "dist-node/index.js"), NODE_WRAPPER, "utf8"); 64 | reporter.created(path.join(out, "dist-node/index.js"), 'main'); 65 | 66 | mkdirp.sync(path.join(out, "dist-types")); 67 | fs.writeFileSync(path.join(out, "dist-types/index.d.ts"), TYPE_DEF, "utf8"); 68 | reporter.created(path.join(out, "dist-types/index.d.ts"), 'types'); 69 | } 70 | -------------------------------------------------------------------------------- /packages/types/dist-node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | class MessageError extends Error { 6 | constructor(msg) { 7 | super(msg); 8 | } 9 | 10 | } 11 | 12 | exports.MessageError = MessageError; 13 | -------------------------------------------------------------------------------- /packages/types/dist-src/index.js: -------------------------------------------------------------------------------- 1 | export class MessageError extends Error { 2 | constructor(msg) { 3 | super(msg); 4 | } 5 | 6 | } -------------------------------------------------------------------------------- /packages/types/dist-types/index.d.ts: -------------------------------------------------------------------------------- 1 | export declare type BuilderOptions = { 2 | cwd: string; 3 | out: string; 4 | options: any; 5 | src: { 6 | loc: string; 7 | entrypoint: string | string[]; 8 | options: any; 9 | files: Array; 10 | }; 11 | watch: string | undefined; 12 | reporter: { 13 | info: (msg: string) => void; 14 | warning: (msg: string) => void; 15 | success: (msg: string) => void; 16 | created: (file: string, entrypoint?: string) => void; 17 | }; 18 | isFull: boolean; 19 | manifest: any; 20 | rollup: any; 21 | }; 22 | export declare class MessageError extends Error { 23 | constructor(msg: string); 24 | } 25 | -------------------------------------------------------------------------------- /packages/types/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/types", 3 | "version": "0.9.2", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@types/node": { 8 | "version": "10.17.17", 9 | "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.17.tgz", 10 | "integrity": "sha512-gpNnRnZP3VWzzj5k3qrpRC6Rk3H/uclhAVo1aIvwzK5p5cOrs9yEyQ8H/HBsBY0u5rrWxXEiVPQ0dEB6pkjE8Q==", 11 | "dev": true 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/types/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/types", 3 | "version": "0.9.2", 4 | "license": "MIT", 5 | "pika": true, 6 | "keywords": [ 7 | "pika-pkg" 8 | ], 9 | "files": [ 10 | "dist-*/", 11 | "assets/", 12 | "bin/" 13 | ], 14 | "sideEffects": false, 15 | "source": "dist-src/index.js", 16 | "main": "dist-node/index.js", 17 | "types": "dist-types/index.d.ts", 18 | "devDependencies": { 19 | "@types/node": "^10.12.18" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/types/pkg/dist-node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | class MessageError extends Error { 6 | constructor(msg) { 7 | super(msg); 8 | } 9 | 10 | } 11 | 12 | exports.MessageError = MessageError; 13 | -------------------------------------------------------------------------------- /packages/types/pkg/dist-src/index.js: -------------------------------------------------------------------------------- 1 | export class MessageError extends Error { 2 | constructor(msg) { 3 | super(msg); 4 | } 5 | 6 | } -------------------------------------------------------------------------------- /packages/types/pkg/dist-types/index.d.ts: -------------------------------------------------------------------------------- 1 | export declare type BuilderOptions = { 2 | cwd: string; 3 | out: string; 4 | options: any; 5 | src: { 6 | loc: string; 7 | entrypoint: string | string[]; 8 | options: any; 9 | files: Array; 10 | }; 11 | watch: string | undefined; 12 | reporter: { 13 | info: (msg: string) => void; 14 | warning: (msg: string) => void; 15 | success: (msg: string) => void; 16 | created: (file: string, entrypoint?: string) => void; 17 | }; 18 | isFull: boolean; 19 | manifest: any; 20 | rollup: any; 21 | }; 22 | export declare class MessageError extends Error { 23 | constructor(msg: string); 24 | } 25 | -------------------------------------------------------------------------------- /packages/types/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pika/types", 3 | "version": "0.9.2", 4 | "license": "MIT", 5 | "pika": true, 6 | "keywords": [ 7 | "pika-pkg" 8 | ], 9 | "files": [ 10 | "dist-*/", 11 | "assets/", 12 | "bin/" 13 | ], 14 | "sideEffects": false, 15 | "source": "dist-src/index.js", 16 | "main": "dist-node/index.js", 17 | "types": "dist-types/index.d.ts", 18 | "devDependencies": { 19 | "@types/node": "^10.12.18" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "module": "ESNext", 5 | "moduleResolution": "Node", 6 | "esModuleInterop": true 7 | } 8 | } 9 | --------------------------------------------------------------------------------