Skip to content

Commit

Permalink
Add new feat to deal with invalid pkg name
Browse files Browse the repository at this point in the history
  • Loading branch information
jalal246 committed Apr 13, 2020
1 parent 3664d9c commit 12c0c80
Show file tree
Hide file tree
Showing 16 changed files with 323 additions and 266 deletions.
4 changes: 2 additions & 2 deletions src/store/StateHandler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-nested-ternary */
import { resolve } from "path";
import { resolve, basename } from "path";
import { validateAccess } from "validate-access";
import { CAMEL_CASE, OUTPUT, ENTRIES, ALIAS } from "../constants";

Expand All @@ -17,7 +17,7 @@ class StateHandler extends State {
extractName() {
const outputOpt = this.opts[OUTPUT];

const chosen = outputOpt || this.pkgName;
const chosen = outputOpt || this.pkgName || basename(this.pkgPath);

return this.opts[CAMEL_CASE] ? camelizeOutputBuild(chosen) : chosen;
}
Expand Down
274 changes: 274 additions & 0 deletions test/__snapshots__/production.test.js.snap

Large diffs are not rendered by default.

55 changes: 30 additions & 25 deletions test/production.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,39 @@ jest.setTimeout(30000);

// ["basic-multi-entries-json", "pure", "alias"];
describe("builderz working for single package", () => {
it.each(["basic-multi-entries-json", "pure", "alias"])(
"%s",
async (pkgName) => {
const pathPure = resolve(__dirname, "samples", pkgName);
const distPath = resolve(pathPure, "dist");
it.each([
// "basic-multi-entries-json",
// "pure",
// "alias",
// "basic-json",
// "shebang",
// "pretty",
"no-pkg-name",
])("%s", async (pkgName) => {
const pathPure = resolve(__dirname, "samples", pkgName);
const distPath = resolve(pathPure, "dist");

try {
await builderz({
cleanBuild: true,
pkgPaths: [resolve(__dirname, pathPure)],
});
try {
await builderz({
cleanBuild: true,
pkgPaths: [resolve(__dirname, pathPure)],
});

const files = readdirSync(distPath);
expect(files.length).toMatchSnapshot();
const files = readdirSync(distPath);
expect(files.length).toMatchSnapshot();

files
.filter((file) => !/\.map$/.test(file))
.sort((file) => (/modern/.test(file) ? 1 : 0))
.forEach((file) => {
expect(
readFileSync(resolve(distPath, file)).toString("utf8")
).toMatchSnapshot();
});
files
.filter((file) => !/\.map$/.test(file))
.sort((file) => (/modern/.test(file) ? 1 : 0))
.forEach((file) => {
expect(
readFileSync(resolve(distPath, file)).toString("utf8")
).toMatchSnapshot();
});

// await del(distPath);
} catch (err) {
console.error(err);
}
// await del(distPath);
} catch (err) {
console.error(err);
}
);
});
});
47 changes: 0 additions & 47 deletions test/samples/packages-valid/folo-forms/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/samples/packages-valid/folo-forms/src/index.js

This file was deleted.

46 changes: 0 additions & 46 deletions test/samples/packages-valid/folo-layout/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/samples/packages-valid/folo-layout/src/index.js

This file was deleted.

35 changes: 0 additions & 35 deletions test/samples/packages-valid/folo-utils/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/samples/packages-valid/folo-utils/src/index.js

This file was deleted.

49 changes: 0 additions & 49 deletions test/samples/packages-valid/folo-values/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/samples/packages-valid/folo-values/src/index.js

This file was deleted.

42 changes: 0 additions & 42 deletions test/samples/packages-valid/folo-withcontext/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/samples/packages-valid/folo-withcontext/src/index.js

This file was deleted.

9 changes: 8 additions & 1 deletion test/samples/pretty/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"name": "pretty"
"name": "pretty",
"builderz": {
"formats": [
"cjs"
],
"sourcemap": false,
"banner": "#!/usr/bin/env node"
}
}
9 changes: 8 additions & 1 deletion test/samples/shebang/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"name": "shebang"
"name": "shebang",
"builderz": {
"formats": [
"cjs"
],
"sourcemap": false,
"banner": "#!/usr/bin/env node"
}
}
4 changes: 1 addition & 3 deletions test/samples/shebang/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

export function foo() {
return 'hello world';
return "hello world";
}

0 comments on commit 12c0c80

Please sign in to comment.