Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

mkdist

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mkdist - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

41

CHANGELOG.md

@@ -5,3 +5,3 @@ # Changelog

### [0.1.4](https://github.com/nuxt-contrib/mkdist/compare/v0.1.3...v0.1.4) (2021-04-07)
### [0.1.5](https://github.com/unjs/mkdist/compare/v0.1.4...v0.1.5) (2021-04-08)

@@ -11,14 +11,21 @@

* support cleanDist option ([f613c17](https://github.com/nuxt-contrib/mkdist/commit/f613c17b6a15c749c58ca395ef1358ff008311e3))
* generate declaration files ([#4](https://github.com/unjs/mkdist/issues/4)) ([4b54426](https://github.com/unjs/mkdist/commit/4b5442606f6c0f066625252700485afaa4c05a75))
### [0.1.3](https://github.com/nuxt-contrib/mkdist/compare/v0.1.2...v0.1.3) (2021-03-30)
### [0.1.4](https://github.com/unjs/mkdist/compare/v0.1.3...v0.1.4) (2021-04-07)
### Features
* support cleanDist option ([f613c17](https://github.com/unjs/mkdist/commit/f613c17b6a15c749c58ca395ef1358ff008311e3))
### [0.1.3](https://github.com/unjs/mkdist/compare/v0.1.2...v0.1.3) (2021-03-30)
### Bug Fixes
* unlink before cleaning up dist dir ([c8cb2b8](https://github.com/nuxt-contrib/mkdist/commit/c8cb2b8a30e7ada0ad2d7383bdb8e9efdb57120e))
* unlink before cleaning up dist dir ([c8cb2b8](https://github.com/unjs/mkdist/commit/c8cb2b8a30e7ada0ad2d7383bdb8e9efdb57120e))
### [0.1.2](https://github.com/nuxt-contrib/mkdist/compare/v0.1.1...v0.1.2) (2021-03-06)
### [0.1.2](https://github.com/unjs/mkdist/compare/v0.1.1...v0.1.2) (2021-03-06)
### [0.1.1](https://github.com/nuxt-contrib/mkdist/compare/v0.1.0...v0.1.1) (2021-01-17)
### [0.1.1](https://github.com/unjs/mkdist/compare/v0.1.0...v0.1.1) (2021-01-17)

@@ -28,5 +35,5 @@

* **pkg:** use siroc build ([ec85042](https://github.com/nuxt-contrib/mkdist/commit/ec85042c544d7dad09dbf13517dfa47f9feb04e2))
* **pkg:** use siroc build ([ec85042](https://github.com/unjs/mkdist/commit/ec85042c544d7dad09dbf13517dfa47f9feb04e2))
## [0.1.0](https://github.com/nuxt-contrib/mkdist/compare/v0.0.5...v0.1.0) (2021-01-17)
## [0.1.0](https://github.com/unjs/mkdist/compare/v0.0.5...v0.1.0) (2021-01-17)

@@ -36,5 +43,5 @@

* fix binary name ([95e1695](https://github.com/nuxt-contrib/mkdist/commit/95e1695861b4495b7025800112d8eb6b574c1ed2))
* fix binary name ([95e1695](https://github.com/unjs/mkdist/commit/95e1695861b4495b7025800112d8eb6b574c1ed2))
### [0.0.5](https://github.com/nuxt-contrib/mkdist/compare/v0.0.4...v0.0.5) (2021-01-15)
### [0.0.5](https://github.com/unjs/mkdist/compare/v0.0.4...v0.0.5) (2021-01-15)

@@ -44,5 +51,5 @@

* bypass `.d.ts` files ([142f0ce](https://github.com/nuxt-contrib/mkdist/commit/142f0cea4f9a6f6cb90339e2bcc07197535f3ac4))
* bypass `.d.ts` files ([142f0ce](https://github.com/unjs/mkdist/commit/142f0cea4f9a6f6cb90339e2bcc07197535f3ac4))
### [0.0.4](https://github.com/nuxt-contrib/mkdist/compare/v0.0.3...v0.0.4) (2021-01-15)
### [0.0.4](https://github.com/unjs/mkdist/compare/v0.0.3...v0.0.4) (2021-01-15)

@@ -52,7 +59,7 @@

* use proper bin ([e763270](https://github.com/nuxt-contrib/mkdist/commit/e763270155b006ce5d42522cd5172170b6c135a9))
* use proper bin ([e763270](https://github.com/unjs/mkdist/commit/e763270155b006ce5d42522cd5172170b6c135a9))
### [0.0.3](https://github.com/nuxt-contrib/mkdist/compare/v0.0.2...v0.0.3) (2021-01-14)
### [0.0.3](https://github.com/unjs/mkdist/compare/v0.0.2...v0.0.3) (2021-01-14)
### [0.0.2](https://github.com/nuxt-contrib/mkdist/compare/v0.0.1...v0.0.2) (2021-01-14)
### [0.0.2](https://github.com/unjs/mkdist/compare/v0.0.1...v0.0.2) (2021-01-14)

@@ -62,5 +69,5 @@

* support format option ([c70f54e](https://github.com/nuxt-contrib/mkdist/commit/c70f54e32769d45485096e334ed88ab0ba709209))
* **cli:** support src, dist and help arguments ([5f3606d](https://github.com/nuxt-contrib/mkdist/commit/5f3606d33b490ba3558148691d367d6caad9aa89))
* support format option ([c70f54e](https://github.com/unjs/mkdist/commit/c70f54e32769d45485096e334ed88ab0ba709209))
* **cli:** support src, dist and help arguments ([5f3606d](https://github.com/unjs/mkdist/commit/5f3606d33b490ba3558148691d367d6caad9aa89))
### 0.0.1 (2021-01-14)

@@ -14,2 +14,22 @@ #!/usr/bin/env node

function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
const mri__default = /*#__PURE__*/_interopDefaultLegacy(mri);

@@ -19,2 +39,63 @@ const globby__default = /*#__PURE__*/_interopDefaultLegacy(globby);

const compilerOptions = {
allowJs: true,
declaration: true,
incremental: true,
skipLibCheck: true,
emitDeclarationOnly: true
};
let _ts;
async function getTs() {
if (!_ts) {
try {
_ts = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('typescript')); });
} catch (err) {
console.warn("[mkdist] Could not load `typescript` for generating types. Do you have it installed?");
throw err;
}
}
return _ts;
}
const vfs = new Map();
let _tsHost;
async function getTsHost() {
if (!_tsHost) {
const ts = await getTs();
_tsHost = ts.createCompilerHost(compilerOptions);
}
_tsHost.writeFile = (fileName, declaration) => {
vfs.set(fileName, declaration);
};
const _readFile = _tsHost.readFile;
_tsHost.readFile = (filename) => {
if (vfs.has(filename)) {
return vfs.get(filename);
}
return _readFile(filename);
};
return _tsHost;
}
async function getDeclaration(contents, filename = "_input.ts") {
const dtsFilename = filename.replace(/\.(ts|js)$/, ".d.ts");
if (vfs.has(dtsFilename)) {
return vfs.get(dtsFilename);
}
try {
const ts = await getTs();
const host = await getTsHost();
if (vfs.has(filename)) {
throw new Error("Race condition for generating " + filename);
}
vfs.set(filename, contents);
const program = ts.createProgram([filename], compilerOptions, host);
await program.emit();
const result = vfs.get(dtsFilename);
vfs.delete(filename);
return result;
} catch (err) {
console.warn(`Could not generate declaration file for ${filename}:`, err);
return "";
}
}
let esbuildService;

@@ -31,2 +112,3 @@ function transform(input, options) {

const jsLoader = async (input, {options}) => {
var _a;
if (![".ts", ".js"].includes(input.extension) || input.path.endsWith(".d.ts")) {

@@ -36,2 +118,13 @@ return;

let contents = await input.getContents();
const declaration = [];
if (options.declaration && !((_a = input.srcPath) == null ? void 0 : _a.endsWith(".d.ts"))) {
const dtsContents = await getDeclaration(contents, input.srcPath);
if (dtsContents) {
declaration.push({
contents: dtsContents,
path: input.path,
extension: ".d.ts"
});
}
}
if (input.extension === ".ts") {

@@ -48,3 +141,4 @@ contents = await transform(contents, {loader: "ts"}).then((r) => r.code);

extension: ".js"
}
},
...declaration
];

@@ -64,5 +158,6 @@ };

const extension = "." + lang;
const [scriptFile] = await loadFile({
const [scriptFile, ...declaration] = await loadFile({
getContents: () => script,
path: `_index${extension}`,
path: `${input.path}${extension}`,
srcPath: `${input.srcPath}${extension}`,
extension

@@ -78,3 +173,4 @@ }) || [];

${scriptFile.contents}</script>`)
}
},
...declaration
];

@@ -125,3 +221,4 @@ };

const {loadFile} = createLoader({
format: options.format
format: options.format,
declaration: options.declaration
});

@@ -155,3 +252,3 @@ for (const file of files) {

if (args.help) {
console.log("Usage: npx mkdist [rootDir] [--src=src] [--dist=dist] [--format=cjs|esm]");
console.log("Usage: npx mkdist [rootDir] [--src=src] [--dist=dist] [--format=cjs|esm] [-d|--declaration]");
process.exit(0);

@@ -163,3 +260,4 @@ }

distDir: args.dist,
format: args.format
format: args.format,
declaration: Boolean(args.declaration || args.d)
});

@@ -166,0 +264,0 @@ console.log(writtenFiles.map((f) => `- ${f}`).join("\n"));

@@ -21,2 +21,3 @@ interface InputFile {

format?: 'cjs' | 'esm';
declaration?: boolean;
};

@@ -28,2 +29,3 @@ }

format?: LoaderContext['options']['format'];
declaration?: LoaderContext['options']['declaration'];
}

@@ -37,2 +39,3 @@

format?: CreateLoaderOptions['format'];
declaration?: CreateLoaderOptions['declaration'];
}

@@ -39,0 +42,0 @@ declare function mkdist(options?: mkdistOptions): Promise<{

@@ -13,5 +13,86 @@ 'use strict';

function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
const globby__default = /*#__PURE__*/_interopDefaultLegacy(globby);
const jiti__default = /*#__PURE__*/_interopDefaultLegacy(jiti);
const compilerOptions = {
allowJs: true,
declaration: true,
incremental: true,
skipLibCheck: true,
emitDeclarationOnly: true
};
let _ts;
async function getTs() {
if (!_ts) {
try {
_ts = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('typescript')); });
} catch (err) {
console.warn("[mkdist] Could not load `typescript` for generating types. Do you have it installed?");
throw err;
}
}
return _ts;
}
const vfs = new Map();
let _tsHost;
async function getTsHost() {
if (!_tsHost) {
const ts = await getTs();
_tsHost = ts.createCompilerHost(compilerOptions);
}
_tsHost.writeFile = (fileName, declaration) => {
vfs.set(fileName, declaration);
};
const _readFile = _tsHost.readFile;
_tsHost.readFile = (filename) => {
if (vfs.has(filename)) {
return vfs.get(filename);
}
return _readFile(filename);
};
return _tsHost;
}
async function getDeclaration(contents, filename = "_input.ts") {
const dtsFilename = filename.replace(/\.(ts|js)$/, ".d.ts");
if (vfs.has(dtsFilename)) {
return vfs.get(dtsFilename);
}
try {
const ts = await getTs();
const host = await getTsHost();
if (vfs.has(filename)) {
throw new Error("Race condition for generating " + filename);
}
vfs.set(filename, contents);
const program = ts.createProgram([filename], compilerOptions, host);
await program.emit();
const result = vfs.get(dtsFilename);
vfs.delete(filename);
return result;
} catch (err) {
console.warn(`Could not generate declaration file for ${filename}:`, err);
return "";
}
}
let esbuildService;

@@ -28,2 +109,3 @@ function transform(input, options) {

const jsLoader = async (input, {options}) => {
var _a;
if (![".ts", ".js"].includes(input.extension) || input.path.endsWith(".d.ts")) {

@@ -33,2 +115,13 @@ return;

let contents = await input.getContents();
const declaration = [];
if (options.declaration && !((_a = input.srcPath) == null ? void 0 : _a.endsWith(".d.ts"))) {
const dtsContents = await getDeclaration(contents, input.srcPath);
if (dtsContents) {
declaration.push({
contents: dtsContents,
path: input.path,
extension: ".d.ts"
});
}
}
if (input.extension === ".ts") {

@@ -45,3 +138,4 @@ contents = await transform(contents, {loader: "ts"}).then((r) => r.code);

extension: ".js"
}
},
...declaration
];

@@ -61,5 +155,6 @@ };

const extension = "." + lang;
const [scriptFile] = await loadFile({
const [scriptFile, ...declaration] = await loadFile({
getContents: () => script,
path: `_index${extension}`,
path: `${input.path}${extension}`,
srcPath: `${input.srcPath}${extension}`,
extension

@@ -75,3 +170,4 @@ }) || [];

${scriptFile.contents}</script>`)
}
},
...declaration
];

@@ -122,3 +218,4 @@ };

const {loadFile} = createLoader({
format: options.format
format: options.format,
declaration: options.declaration
});

@@ -125,0 +222,0 @@ for (const file of files) {

{
"name": "mkdist",
"version": "0.1.4",
"description": "",
"repository": "nuxt-contrib/mkdist",
"version": "0.1.5",
"description": "Lightweight file-to-file transformer",
"repository": "unjs/mkdist",
"license": "MIT",

@@ -45,3 +45,11 @@ "main": "dist/index.js",

"typescript": "latest"
},
"peerDependencies": {
"typescript": ">=3.7"
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
}
}
}

@@ -10,26 +10,29 @@ # mkdist

Lightweight file-to-file transpiler
> Lightweight file-to-file transformer
## Features
✅ Copies all assets
- Vue SFC support (`<script>` tag transpilation)
- Typescript support (via [esbuild](https://github.com/evanw/esbuild))
- Automatic copying of assets
✅ Supports [Vue Single File Components](https://vuejs.org/v2/guide/single-file-components.html)
## Usage
✅ Fast and minimal transform by [esbuild](https://github.com/evanw/esbuild)
```bash
npx mkdist [rootDir] [--src=src] [--dist=dist] [--format=cjs|esm]
```
✅ `.d.ts` generation for `.ts`, `.js` and `.vue` files
## Compared to `tsc` / `babel`
## ❓ Why?
✅ Copies all assets (not just TS)
Bundling libraries isn't always the best choice:
✅ Supports TypeScript for Vue SFC
- We loose original file structure
- We loose modern syntax by transpiling in bundle
- We loose critical-css by extracting css to a global dist (vue)
- Dependencies will be always imported from bundle even if not used (a second bundling step might fix this but it usually won't happen in development and for dependencies with side-effect)
✅ Faster, thanks to esbuild
While there are tools like [tsc](https://www.typescriptlang.org/docs/handbook/compiler-options.html) and [@babel/cli](https://babeljs.io/docs/en/babel-cli), they mostly focus on transpiling rather than keeping source level quality. Also they lack support for handling custom extensions like `.vue` and copying assets.
🚧 (WIP) `.d.ts` generation
## 🚀 Usage
```bash
npx mkdist [rootDir] [--src=src] [--dist=dist] [--format=cjs|esm] [-d|--declaration]
```
## License

@@ -46,6 +49,6 @@

[github-actions-src]: https://img.shields.io/github/workflow/status/nuxt-contrib/mkdist/ci/main?style=flat-square
[github-actions-href]: https://github.com/nuxt-contrib/mkdist/actions?query=workflow%3Aci
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/mkdist/ci/main?style=flat-square
[github-actions-href]: https://github.com/unjs/mkdist/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/nuxt-contrib/mkdist/main?style=flat-square
[codecov-href]: https://codecov.io/gh/nuxt-contrib/mkdist
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/mkdist/main?style=flat-square
[codecov-href]: https://codecov.io/gh/unjs/mkdist
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc