Skip to content

Commit ed6262c

Browse files
committed
bundle bin to avoid bs-platform build on postinstall + artifacts issues
1 parent c62989f commit ed6262c

17 files changed

+1889
-141
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ package-lock.json
1212
**/lib/ocaml
1313
**/.merlin
1414
*.bs.js
15+
16+
# webpack build
17+
dist

__tests__/Test.proxy.js

-5
This file was deleted.

__tests__/Test.re

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ let testAll = svg => {
2929
};
3030

3131
describe("simple svg", () =>
32-
readFileSync("./test/simple.svg", `utf8)->testAll
32+
readFileSync("./__tests__/fixtures/simple.svg", `utf8)->testAll
3333
);
3434

3535
describe("edge case width svg", () =>
36-
readFileSync("./test/edge-case-width.svg", `utf8)->testAll
36+
readFileSync("./__tests__/fixtures/edge-case-width.svg", `utf8)->testAll
3737
);
3838

3939
describe("clean & minimal svg", () =>
40-
readFileSync("./test/clean.svg", `utf8)->testAll
40+
readFileSync("./__tests__/fixtures/clean.svg", `utf8)->testAll
4141
);
4242

4343
describe("sketch export", () =>
44-
readFileSync("./test/sketch-export.svg", `utf8)->testAll
44+
readFileSync("./__tests__/fixtures/sketch-export.svg", `utf8)->testAll
4545
);
4646

4747
describe("with fill", () =>
48-
readFileSync("./test/with-fill.svg", `utf8)->testAll
48+
readFileSync("./__tests__/fixtures/with-fill.svg", `utf8)->testAll
4949
);
5050

5151
describe("with stroke", () =>
52-
readFileSync("./test/with-stroke.svg", `utf8)->testAll
52+
readFileSync("./__tests__/fixtures/with-stroke.svg", `utf8)->testAll
5353
);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

bin.js

+1-77
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,3 @@
11
#!/usr/bin/env node
22
"use strict";
3-
const meow = require("meow");
4-
5-
// UPDATE README IF YOU UPDATE THIS PLEASE
6-
const cli = meow(
7-
`
8-
Usage
9-
$ react-from-svg <sourcePath> <outputPath> [--with-native|--with-web]
10-
11-
Options
12-
--with-native, -native Output code for react-native-svg
13-
--with-web, -web Output code for DOM. If --with-native is also used, will be output as .web.js files
14-
--with-reason, -bs Output ReasonML bindings code
15-
--remove-fill, -rf Remove all 'fill' properties from SVGs, convenient for icons
16-
--remove-stroke, -rs Remove all 'stroke' properties from SVGs, convenient for icons
17-
--commonjs, -cjs Export as commonjs instead of es6 import/export
18-
--bs-module-path, -bsp Allow to customise ReasonML output path
19-
20-
Example
21-
$ react-from-svg assets/svgs src/Svgs --remove-fill
22-
`,
23-
{
24-
flags: {
25-
"with-native": { type: "boolean", alias: "native" },
26-
"with-web": { type: "boolean", alias: "web" },
27-
"with-reason": { type: "boolean", alias: "bs" },
28-
"remove-fill": { type: "boolean", alias: "rf" },
29-
"remove-stroke": { type: "boolean", alias: "rs" },
30-
commonjs: { type: "boolean", alias: "cjs" },
31-
"bs-module-path": { type: "string", alias: "bsp" },
32-
},
33-
},
34-
);
35-
36-
if (cli.flags.withNative === undefined && cli.flags.withWeb === undefined) {
37-
console.error(
38-
"You should at least choose an option between --with-native or --with web!",
39-
);
40-
cli.showHelp();
41-
process.exit(1);
42-
}
43-
44-
///
45-
46-
let compiledArtifact = "./lib/js/src/Transformer.bs.js";
47-
let transformer;
48-
try {
49-
transformer = require(compiledArtifact);
50-
} catch (e) {
51-
console.log(
52-
"react-from-svg: Missing compiled " + compiledArtifact + ", rebuilding",
53-
);
54-
require("child_process").execSync("bsb -clean-world -make-world", {
55-
cwd: __dirname,
56-
stdio: "inherit",
57-
});
58-
}
59-
60-
setTimeout(function() {
61-
try {
62-
delete require.cache[compiledArtifact];
63-
transformer = require(compiledArtifact);
64-
} catch (e) {
65-
throw new Error(
66-
"react-from-svg: missing compiled script. You might have used a `bsb -clean-world` which is currently causing trouble to the way this bin is generated." +
67-
"\n" +
68-
"***************************************************************************************************************" +
69-
"\n" +
70-
"** Try running this command again, we tried to compile it asynchronously (should be ready as you read this). **" +
71-
"\n" +
72-
"***************************************************************************************************************" +
73-
"\n" +
74-
"If this issue persist, open an issue with as much as information as you can (bsconfig, etc) https://github.com/MoOx/react-from-svg/issues/new",
75-
);
76-
}
77-
78-
transformer.make(cli.input, cli.flags);
79-
}, 0);
3+
require("./dist/bin.js");

bsconfig.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"react-jsx": 3
77
},
88
"package-specs": {
9-
"module": "commonjs"
10-
// "in-source": true
9+
"module": "commonjs",
10+
"in-source": true
1111
},
1212
"suffix": ".bs.js",
1313
"sources": [
@@ -20,6 +20,6 @@
2020
"type": "dev"
2121
}
2222
],
23-
"bs-dependencies": ["reason-future", "reason-react"],
23+
"bs-dependencies": ["reason-future"],
2424
"bs-dev-dependencies": ["@glennsl/bs-jest"]
2525
}

package.json

+15-12
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,40 @@
2121
"react-from-svg": "./bin.js"
2222
},
2323
"files": [
24-
"src",
25-
"!test",
26-
"bin.js",
27-
"bsconfig.json"
24+
"*",
25+
"!.github",
26+
"!.DS_Store",
27+
"!**/*.bs.js",
28+
"!.merlin",
29+
"!lib/bs",
30+
"!lib/ocaml"
2831
],
2932
"scripts": {
30-
"postinstall": "bsb -clean-world -make-world",
33+
"prepare": "bsb -clean-world -make-world && webpack",
3134
"re:clean": "bsb -clean-world",
3235
"re:build": "bsb -make-world",
3336
"svg:format": "find test/components -name \"*.re\" | grep -v \"node_modules\" | xargs bsrefmt --in-place",
34-
"tests": "jest \"__tests__/(.*).proxy.js\"",
35-
"test": "yarn re:clean && yarn re:build && yarn tests",
37+
"tests": "jest",
38+
"test": "yarn re:clean && yarn re:build && yarn tests && webpack",
3639
"release": "npmpub"
3740
},
3841
"dependencies": {
39-
"bs-platform": "^7.2.2",
4042
"camelcase": "^6.0.0",
4143
"glob": "^7.1.3",
4244
"meow": "^6.1.0",
43-
"mkdirp": "^0.5.1",
44-
"reason-future": "^2.4.0",
45-
"reason-react": "^0.7.0"
45+
"mkdirp": "^0.5.1"
4646
},
4747
"devDependencies": {
4848
"@glennsl/bs-jest": "^0.5.1",
49+
"bs-platform": "^7.2.2",
4950
"husky": "^4.2.0",
5051
"jest": "^25.3.0",
5152
"lint-staged": "^10.0.2",
5253
"npmpub": "^5.0.0",
5354
"prettier": "^1.19.1",
54-
"trash-cli": "^1.4.0"
55+
"reason-future": "^2.4.0",
56+
"webpack": "^4.42.1",
57+
"webpack-cli": "^3.3.11"
5558
},
5659
"prettier": {
5760
"trailingComma": "all",

src/bin.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const meow = require("meow");
2+
3+
// UPDATE README IF YOU UPDATE THIS PLEASE
4+
const cli = meow(
5+
`
6+
Usage
7+
$ react-from-svg <sourcePath> <outputPath> [--with-native|--with-web]
8+
9+
Options
10+
--with-native, -native Output code for react-native-svg
11+
--with-web, -web Output code for DOM. If --with-native is also used, will be output as .web.js files
12+
--with-reason, -bs Output ReasonML bindings code
13+
--remove-fill, -rf Remove all 'fill' properties from SVGs, convenient for icons
14+
--remove-stroke, -rs Remove all 'stroke' properties from SVGs, convenient for icons
15+
--commonjs, -cjs Export as commonjs instead of es6 import/export
16+
--bs-module-path, -bsp Allow to customise ReasonML output path
17+
18+
Example
19+
$ react-from-svg assets/svgs src/Svgs --remove-fill
20+
`,
21+
{
22+
flags: {
23+
"with-native": { type: "boolean", alias: "native" },
24+
"with-web": { type: "boolean", alias: "web" },
25+
"with-reason": { type: "boolean", alias: "bs" },
26+
"remove-fill": { type: "boolean", alias: "rf" },
27+
"remove-stroke": { type: "boolean", alias: "rs" },
28+
commonjs: { type: "boolean", alias: "cjs" },
29+
"bs-module-path": { type: "string", alias: "bsp" },
30+
},
31+
},
32+
);
33+
34+
if (cli.flags.withNative === undefined && cli.flags.withWeb === undefined) {
35+
console.error(
36+
"You should at least choose an option between --with-native or --with web!",
37+
);
38+
cli.showHelp();
39+
process.exit(1);
40+
}
41+
42+
require("./Transformer.bs.js").make(cli.input, cli.flags);

webpack.config.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const path = require("path");
2+
3+
module.exports = {
4+
mode: "production",
5+
entry: "./src/bin.js",
6+
output: {
7+
filename: "bin.js",
8+
libraryTarget: "commonjs",
9+
},
10+
target: "node",
11+
externals: {
12+
meow: "meow",
13+
camelcase: "camelcase",
14+
glob: "glob",
15+
mkdirp: "mkdirp",
16+
},
17+
};

0 commit comments

Comments
 (0)