@frozzare/pkg 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -7
- package/package.json +4 -1
- package/.editorconfig +0 -15
- package/.eslintrc +0 -10
- package/.github/renovate.json +0 -14
- package/.github/workflows/nodejs.yml +0 -37
- package/jest.config.js +0 -5
- package/src/index.ts +0 -37
- package/test/__snapshots__/build.test.ts.snap +0 -45
- package/test/build.test.ts +0 -21
- package/test/fixtures/class.ts +0 -3
- package/tsconfig.json +0 -26
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { BuildOptions as ESBuildOptions } from 'esbuild';
|
|
2
2
|
export type BuildOptions = Omit<ESBuildOptions, 'bundle' | 'entryPoints'>;
|
|
3
|
-
export declare const build: (entryPoint: string,
|
|
3
|
+
export declare const build: (entryPoint: string, options?: BuildOptions) => Promise<string | void>;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.build = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const esbuild_1 = require("esbuild");
|
|
10
|
+
const defaultOptions = {
|
|
11
|
+
write: true,
|
|
12
|
+
};
|
|
13
|
+
const build = async (entryPoint, options = {}) => {
|
|
14
|
+
const config = { ...defaultOptions, ...options };
|
|
15
|
+
const out = await (0, esbuild_1.build)({
|
|
6
16
|
...config,
|
|
7
17
|
entryPoints: [entryPoint],
|
|
8
18
|
bundle: true,
|
|
@@ -22,6 +32,7 @@ export const build = async (entryPoint, config = {}) => {
|
|
|
22
32
|
if (!config.write) {
|
|
23
33
|
return text;
|
|
24
34
|
}
|
|
25
|
-
|
|
26
|
-
return !config.write ? text :
|
|
35
|
+
fs_1.default.mkdirSync(path_1.default.dirname(file.path));
|
|
36
|
+
return !config.write ? text : fs_1.default.writeFileSync(file.path, text);
|
|
27
37
|
};
|
|
38
|
+
exports.build = build;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frozzare/pkg",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
"prepublishOnly": "npm run build",
|
|
11
11
|
"test": "jest"
|
|
12
12
|
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
13
16
|
"keywords": [],
|
|
14
17
|
"author": "Fredrik Forsmo <fredrik.forsmo@gmail.com>",
|
|
15
18
|
"license": "MIT",
|
package/.editorconfig
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
root = true
|
|
2
|
-
|
|
3
|
-
[*]
|
|
4
|
-
indent_style = space
|
|
5
|
-
indent_size = 2
|
|
6
|
-
end_of_line = lf
|
|
7
|
-
charset = utf-8
|
|
8
|
-
trim_trailing_whitespace = true
|
|
9
|
-
insert_final_newline = true
|
|
10
|
-
|
|
11
|
-
[*.md]
|
|
12
|
-
trim_trailing_whitespace = false
|
|
13
|
-
|
|
14
|
-
[*.{js,ts}]
|
|
15
|
-
quote_type = single
|
package/.eslintrc
DELETED
package/.github/renovate.json
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
name: build
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- master
|
|
7
|
-
|
|
8
|
-
# Run tests for any PRs.
|
|
9
|
-
pull_request:
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
build:
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
|
|
15
|
-
strategy:
|
|
16
|
-
matrix:
|
|
17
|
-
node-version:
|
|
18
|
-
- 14
|
|
19
|
-
- 16
|
|
20
|
-
- 18
|
|
21
|
-
|
|
22
|
-
steps:
|
|
23
|
-
- uses: actions/checkout@v3
|
|
24
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
25
|
-
uses: actions/setup-node@v3.6.0
|
|
26
|
-
with:
|
|
27
|
-
node-version: ${{ matrix.node-version }}
|
|
28
|
-
- name: npm install
|
|
29
|
-
run: npm install
|
|
30
|
-
- name: npm run lint
|
|
31
|
-
run: npm run lint
|
|
32
|
-
- name: npm run build
|
|
33
|
-
run: npm run build
|
|
34
|
-
- name: npm run test
|
|
35
|
-
run: npm run test
|
|
36
|
-
env:
|
|
37
|
-
CI: true
|
package/jest.config.js
DELETED
package/src/index.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { build as esbuild, BuildOptions as ESBuildOptions } from 'esbuild';
|
|
4
|
-
|
|
5
|
-
export type BuildOptions = Omit<ESBuildOptions, 'bundle' | 'entryPoints'>;
|
|
6
|
-
|
|
7
|
-
export const build = async (entryPoint: string, config: BuildOptions = {}) => {
|
|
8
|
-
const out = await esbuild({
|
|
9
|
-
...config,
|
|
10
|
-
entryPoints: [entryPoint],
|
|
11
|
-
bundle: true,
|
|
12
|
-
write: false,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const file = out.outputFiles[0];
|
|
16
|
-
let text = file.text;
|
|
17
|
-
|
|
18
|
-
if (config.format === 'cjs') {
|
|
19
|
-
const reg = /module.exports = __toCommonJS\((\w+)\);/;
|
|
20
|
-
const match = text.match(reg);
|
|
21
|
-
|
|
22
|
-
if (!match) {
|
|
23
|
-
throw new Error('Failed to find export name');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const name = match?.[1].replace('_exports', '_default');
|
|
27
|
-
text = text.replace(match?.[0] || '', '') + `\nmodule.exports = ${name}`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!config.write) {
|
|
31
|
-
return text;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
fs.mkdirSync(path.dirname(file.path));
|
|
35
|
-
|
|
36
|
-
return !config.write ? text : fs.writeFileSync(file.path, text);
|
|
37
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`build should build cjs 1`] = `
|
|
4
|
-
""use strict";
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
-
|
|
23
|
-
// test/fixtures/class.ts
|
|
24
|
-
var class_exports = {};
|
|
25
|
-
__export(class_exports, {
|
|
26
|
-
default: () => class_default
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
var Test = class {
|
|
30
|
-
};
|
|
31
|
-
var class_default = Test;
|
|
32
|
-
|
|
33
|
-
module.exports = class_default"
|
|
34
|
-
`;
|
|
35
|
-
|
|
36
|
-
exports[`build should build esm 1`] = `
|
|
37
|
-
""use strict";
|
|
38
|
-
(() => {
|
|
39
|
-
// test/fixtures/class.ts
|
|
40
|
-
var Test = class {
|
|
41
|
-
};
|
|
42
|
-
var class_default = Test;
|
|
43
|
-
})();
|
|
44
|
-
"
|
|
45
|
-
`;
|
package/test/build.test.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { build } from '../src';
|
|
2
|
-
|
|
3
|
-
describe('build', () => {
|
|
4
|
-
it('should build esm', async () => {
|
|
5
|
-
const output = await build(`${__dirname}/fixtures/class.ts`, {
|
|
6
|
-
write: false,
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
expect(output).toMatchSnapshot();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should build cjs', async () => {
|
|
13
|
-
const output = await build(`${__dirname}/fixtures/class.ts`, {
|
|
14
|
-
write: false,
|
|
15
|
-
format: 'cjs',
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
expect(output).toMatchSnapshot();
|
|
19
|
-
expect(output).toContain('module.exports = class_default');
|
|
20
|
-
});
|
|
21
|
-
});
|
package/test/fixtures/class.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2018",
|
|
4
|
-
"lib": ["es2018", "dom"],
|
|
5
|
-
"allowJs": false,
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"emitDeclarationOnly": false,
|
|
8
|
-
"outDir": "dist",
|
|
9
|
-
"rootDirs": ["src"],
|
|
10
|
-
"noEmit": false,
|
|
11
|
-
"strict": true,
|
|
12
|
-
"moduleResolution": "node",
|
|
13
|
-
"types": ["node"],
|
|
14
|
-
"allowSyntheticDefaultImports": true,
|
|
15
|
-
"esModuleInterop": true,
|
|
16
|
-
"experimentalDecorators": true,
|
|
17
|
-
"emitDecoratorMetadata": true,
|
|
18
|
-
"skipLibCheck": true,
|
|
19
|
-
"baseUrl": "src",
|
|
20
|
-
"forceConsistentCasingInFileNames": true,
|
|
21
|
-
"noImplicitReturns": true,
|
|
22
|
-
"suppressImplicitAnyIndexErrors": true,
|
|
23
|
-
"noUnusedLocals": true
|
|
24
|
-
},
|
|
25
|
-
"include": ["src"]
|
|
26
|
-
}
|