diff --git a/.eslintignore b/.eslintignore index fa90e51b..a14bf52c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,5 @@ /node_modules src/modules/create-knit-app/template +lib dist build diff --git a/.gitignore b/.gitignore index f2632dfa..d34bb912 100644 --- a/.gitignore +++ b/.gitignore @@ -29,10 +29,14 @@ coverage .idea *.iml .vscode +.merlin # build folders build dist +**/lib/bs +**/lib/ocaml +/lib # OS .DS_Store diff --git a/bsconfig.json b/bsconfig.json new file mode 100644 index 00000000..dd3d3170 --- /dev/null +++ b/bsconfig.json @@ -0,0 +1,16 @@ +{ + "name": "this_just_for_the_root_merlin_file_for_text_editor", + "sources": [ + { + "dir": "src", + "subdirs": [] + } + ], + "bs-dev-dependencies": [ + "immutable-re", + "@knit/is-scoped", + "@knit/path-join", + "@knit/read-pkg" + ], + "generate-merlin": true +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bda75c0e..820d0210 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,7 +1,7 @@ { "version": "0.4.1", "lockfileVersion": 1, - "packageIntegrity": "sha512-VsvokrBAs2H4u0XIEyv7ZKIxG4GkEAdZepZt86Oc8CXuIdoujJ7JrffLK7+V49gewnzpaNlOPzEZHCEVLGDbCQ==", + "packageIntegrity": "sha512-/wYd1J1NAAdP8nrpjAL3QI0Ev+dsUgpgAPDCQAHeo8zl8Ytg8ukvQRChQuN2uHGAIruju4LPWeReGq/y9be9yw==", "dependencies": { "@knit/babel-preset-socks-react": { "version": "file:src/modules/@knit/babel-preset-socks-react", @@ -921,6 +921,11 @@ "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-2.1.3.tgz", "integrity": "sha1-MC3I5eRPPVk3hQhoqrE+EcrD28c=" }, + "bs-platform": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/bs-platform/-/bs-platform-1.7.3.tgz", + "integrity": "sha1-g94BNK/9xyNUVHfOc3YGhH2nAQQ=" + }, "bser": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/bser/-/bser-2.0.0.tgz", @@ -2995,6 +3000,11 @@ "integrity": "sha1-QyNS5XrM2HqzEQ6C0/6g5HgSFW0=", "dev": true }, + "immutable-re": { + "version": "0.0.15", + "resolved": "https://registry.npmjs.org/immutable-re/-/immutable-re-0.0.15.tgz", + "integrity": "sha1-Vqma12R5pf/T/M7BPsK4U9HrzjE=" + }, "imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", diff --git a/package.json b/package.json index e78e22c3..39c94653 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "file-loader": "^0.10.1", "fs-extra": "^3.0.1", "html-webpack-plugin": "^2.28.0", + "immutable-re": "0.0.15", "json-loader": "^0.5.4", "listr": "^0.12.0", "listr-silent-renderer": "^1.1.1", @@ -61,10 +62,13 @@ }, "scripts": { "precommit": "lint-staged", - "copy": "rm -rf dist && rm -rf build && yarn knit -- copy --ignore-path=@knit/**/{__mocks__,__tests__,*.js}", + "copy": "rm -rf dist && rm -rf build && yarn knit -- copy --ignore-path=@knit/**/{__mocks__,__tests__,bs,*.js,*.re,}", "build-lib": "NODE_ENV=production babel src/modules/ -d dist/ --ignore __mocks__,__tests__,jest,create", "build-cjs": "NODE_ENV=production yarn knit -- exec --concurrently --scope modified --include=@knit --exclude=jest -- babel . -d ROOT_DIR/dist/KNIT_MODULE_NAME --ignore __mocks__,__tests__,jest,create", - "build-packages": "yarn copy && yarn build-cjs && yarn knit -- stitch --scope modified", + "build-bsb": "NODE_ENV=production yarn knit -- exec --concurrently --include=is-scoped path-join read-pkg -- bsb -make-world", + "build-ocaml": "yarn knit -- exec --concurrently --include=is-scoped path-join read-pkg -- knit copy --workingDir lib/bs --outputDir lib/ocaml", + "build-bsb-w": "NODE_ENV=production yarn knit -- exec --concurrently --include=is-scoped path-join read-pkg -- bsb -w", + "build-packages": "yarn build-bsb && yarn copy && yarn build-cjs && yarn knit -- stitch --scope modified", "version": "yarn knit -- exec --scope modified -- npm version --no-git-tag-version $npm_package_version && git add .", "publish-packages": "yarn knit -- exec --scope unpublished --working-dir build -- npm publish", "knit": "babel-node src/modules/@knit/knit/bin/cli.js", @@ -109,6 +113,7 @@ "babel-plugin-array-includes": "2.0.3", "babel-plugin-transform-flow-strip-types": "^6.22.0", "babel-plugin-transform-runtime": "^6.23.0", + "bs-platform": "1.7.3", "eslint": "^3.16.1", "eslint-config-google": "0.7.1", "eslint-config-prettier": "2.1.1", diff --git a/src/modules/@knit/find-dependencies/index.js b/src/modules/@knit/find-dependencies/index.js index a04cebec..ca884d04 100644 --- a/src/modules/@knit/find-dependencies/index.js +++ b/src/modules/@knit/find-dependencies/index.js @@ -3,7 +3,7 @@ import type { TPkgJson, TPkgJsonDeps } from "@knit/needle"; import depcheck from "@knit/depcheck"; -import pathJoin from "@knit/path-join"; +import { pathJoin } from "@knit/path-join"; import readPkg from "@knit/read-pkg"; export type TModules = Array; diff --git a/src/modules/@knit/find-modified-packages/index.js b/src/modules/@knit/find-modified-packages/index.js index fc4ed5e6..a8f4ad34 100644 --- a/src/modules/@knit/find-modified-packages/index.js +++ b/src/modules/@knit/find-modified-packages/index.js @@ -5,7 +5,7 @@ import type { TModules } from "@knit/knit-core"; import execa from "execa"; import { makeDependencyMap } from "@knit/find-dependencies"; -import isScoped from "@knit/is-scoped"; +import { isScoped } from "@knit/is-scoped"; type TResolveCascadingUpdates = ( modules: TModules, diff --git a/src/modules/@knit/find-packages/index.js b/src/modules/@knit/find-packages/index.js index 7abdad66..29a72d32 100644 --- a/src/modules/@knit/find-packages/index.js +++ b/src/modules/@knit/find-packages/index.js @@ -2,8 +2,8 @@ import fs from "fs-extra"; -import isScoped from "@knit/is-scoped"; -import pathJoin from "@knit/path-join"; +import { isScoped } from "@knit/is-scoped"; +import { pathJoin } from "@knit/path-join"; import getPackageFromDir from "@knit/get-package-from-dir"; import readPkg from "@knit/read-pkg"; diff --git a/src/modules/@knit/is-scoped/IsScoped.re b/src/modules/@knit/is-scoped/IsScoped.re new file mode 100644 index 00000000..01a3d638 --- /dev/null +++ b/src/modules/@knit/is-scoped/IsScoped.re @@ -0,0 +1,3 @@ +/*let isScoped package => package.[0] === '@';*/ +let isScoped (package: string) :Js.boolean => + Js.Boolean.to_js_boolean (Js.String.get package 0 === "@"); \ No newline at end of file diff --git a/src/modules/@knit/is-scoped/__tests__/unit.test.js b/src/modules/@knit/is-scoped/__tests__/unit.test.js index e8aabce6..0149b982 100644 --- a/src/modules/@knit/is-scoped/__tests__/unit.test.js +++ b/src/modules/@knit/is-scoped/__tests__/unit.test.js @@ -1,4 +1,4 @@ -const is = require(".."); +import { isScoped as is } from ".."; describe("isScoped", () => { it("knows if package is scoped", () => { diff --git a/src/modules/@knit/is-scoped/bsconfig.json b/src/modules/@knit/is-scoped/bsconfig.json new file mode 100644 index 00000000..9003ebb1 --- /dev/null +++ b/src/modules/@knit/is-scoped/bsconfig.json @@ -0,0 +1,9 @@ +{ + "name": "@knit/is-scoped", + "sources": ".", + "package-specs": ["commonjs"], + "bsc-flags": [ + "-bs-cross-module-opt" + ], + "generate-merlin": false +} diff --git a/src/modules/@knit/is-scoped/index.js b/src/modules/@knit/is-scoped/index.js index ebfe844e..a6decebb 100644 --- a/src/modules/@knit/is-scoped/index.js +++ b/src/modules/@knit/is-scoped/index.js @@ -3,4 +3,4 @@ type TIsScoped = (m: string) => boolean; const isScoped: TIsScoped = module => module[0] === "@"; -export default isScoped; +export { isScoped }; diff --git a/src/modules/@knit/is-scoped/lib/js/isScoped.js b/src/modules/@knit/is-scoped/lib/js/isScoped.js new file mode 100644 index 00000000..9638a0fb --- /dev/null +++ b/src/modules/@knit/is-scoped/lib/js/isScoped.js @@ -0,0 +1,15 @@ +// Generated by BUCKLESCRIPT VERSION 1.7.3, PLEASE EDIT WITH CARE +'use strict'; + + +function isScoped($$package) { + var b = +($$package[0] === "@"); + if (b) { + return true; + } else { + return false; + } +} + +exports.isScoped = isScoped; +/* No side effect */ diff --git a/src/modules/@knit/is-scoped/package.json b/src/modules/@knit/is-scoped/package.json index b5e215ed..e86390a6 100644 --- a/src/modules/@knit/is-scoped/package.json +++ b/src/modules/@knit/is-scoped/package.json @@ -1,4 +1,5 @@ { "name": "@knit/is-scoped", - "version": "0.4.0" + "version": "0.4.0", + "main": "lib/js/isScoped" } diff --git a/src/modules/@knit/knit/tasks/exec.js b/src/modules/@knit/knit/tasks/exec.js index 6f5377ce..19cde72b 100644 --- a/src/modules/@knit/knit/tasks/exec.js +++ b/src/modules/@knit/knit/tasks/exec.js @@ -5,7 +5,7 @@ import type { TModules } from "@knit/knit-core"; const Listr = require("listr"); const needle = require("@knit/needle"); -const pathJoin = require("@knit/path-join"); +import { pathJoin } from "@knit/path-join"; const execa = require("execa"); type TCtx = { diff --git a/src/modules/@knit/knit/tasks/publish.js b/src/modules/@knit/knit/tasks/publish.js index 650f0545..cad9bd1e 100644 --- a/src/modules/@knit/knit/tasks/publish.js +++ b/src/modules/@knit/knit/tasks/publish.js @@ -7,7 +7,7 @@ import yarn from "@knit/yarn-utils"; const Listr = require("listr"); -const pathJoin = require("@knit/path-join"); +import { pathJoin } from "@knit/path-join"; const needle = require("@knit/needle"); type TCtx = { diff --git a/src/modules/@knit/knit/tasks/run.js b/src/modules/@knit/knit/tasks/run.js index 075aafd5..c68ea79d 100644 --- a/src/modules/@knit/knit/tasks/run.js +++ b/src/modules/@knit/knit/tasks/run.js @@ -6,7 +6,7 @@ import readPkg from "@knit/read-pkg"; const Listr = require("listr"); -const pathJoin = require("@knit/path-join"); +import { pathJoin } from "@knit/path-join"; const needle = require("@knit/needle"); const yarn = require("@knit/yarn-utils"); diff --git a/src/modules/@knit/knit/tasks/stitch.js b/src/modules/@knit/knit/tasks/stitch.js index f844ee72..3de51cd9 100644 --- a/src/modules/@knit/knit/tasks/stitch.js +++ b/src/modules/@knit/knit/tasks/stitch.js @@ -9,7 +9,7 @@ import writePkg from "write-pkg"; import { findDependencies } from "@knit/find-dependencies"; const knit = require("@knit/knit-core"); -const pathJoin = require("@knit/path-join"); +import { pathJoin } from "@knit/path-join"; const needle = require("@knit/needle"); type TCtx = { diff --git a/src/modules/@knit/path-join/PathJoin.re b/src/modules/@knit/path-join/PathJoin.re new file mode 100644 index 00000000..8b1baba2 --- /dev/null +++ b/src/modules/@knit/path-join/PathJoin.re @@ -0,0 +1,5 @@ +external join : string => string => string = "" [@@bs.module "path"]; + +external sep : string = "" [@@bs.module "path"]; + +let pathJoin dir_path package => Js.String.replace "/" sep (join dir_path package); \ No newline at end of file diff --git a/src/modules/@knit/path-join/__tests__/unit.test.js b/src/modules/@knit/path-join/__tests__/unit.test.js index 14940128..84bc4d8f 100644 --- a/src/modules/@knit/path-join/__tests__/unit.test.js +++ b/src/modules/@knit/path-join/__tests__/unit.test.js @@ -2,20 +2,15 @@ const path = require("path"); -const pj = require(".."); +import { pathJoin as pj } from ".."; describe("pathJoin", () => { - it("still works like path.join", () => { - expect(pj("foo", "bar", "module")).toBe(path.join("foo", "bar", "module")); - }); it("create path when passed scoped module", () => { - expect(pj("foo", "bar", "@scope/package")).toBe( - path.join("foo", "bar", "@scope", "package") + expect(pj("foo", "@scope/package")).toBe( + path.join("foo", "@scope", "package") ); }); it("keep abs path", () => { - expect(pj("/foo", "bar", "package")).toBe( - path.join("/foo", "bar", "package") - ); + expect(pj("/foo", "package")).toBe(path.join("/foo", "package")); }); }); diff --git a/src/modules/@knit/path-join/bsconfig.json b/src/modules/@knit/path-join/bsconfig.json new file mode 100644 index 00000000..4d6f7ed5 --- /dev/null +++ b/src/modules/@knit/path-join/bsconfig.json @@ -0,0 +1,9 @@ +{ + "name": "@knit/path-join", + "sources": ".", + "package-specs": ["commonjs"], + "bsc-flags": [ + "-bs-cross-module-opt" + ], + "generate-merlin": false +} diff --git a/src/modules/@knit/path-join/index.js b/src/modules/@knit/path-join/index.js index 3a7fcd58..53bbc071 100644 --- a/src/modules/@knit/path-join/index.js +++ b/src/modules/@knit/path-join/index.js @@ -6,4 +6,4 @@ type TPathJoin = (p: string) => string; const pathJoin: TPathJoin = (...paths) => path.join(...paths).replace("/", path.sep); -module.exports = pathJoin; +export { pathJoin }; diff --git a/src/modules/@knit/path-join/lib/js/pathJoin.js b/src/modules/@knit/path-join/lib/js/pathJoin.js new file mode 100644 index 00000000..6746c7ee --- /dev/null +++ b/src/modules/@knit/path-join/lib/js/pathJoin.js @@ -0,0 +1,11 @@ +// Generated by BUCKLESCRIPT VERSION 1.7.3, PLEASE EDIT WITH CARE +'use strict'; + +var Path = require("path"); + +function pathJoin(dir_path, $$package) { + return Path.join(dir_path, $$package).replace("/", Path.sep); +} + +exports.pathJoin = pathJoin; +/* path Not a pure module */ diff --git a/src/modules/@knit/path-join/package.json b/src/modules/@knit/path-join/package.json index e91b1daf..f026a989 100644 --- a/src/modules/@knit/path-join/package.json +++ b/src/modules/@knit/path-join/package.json @@ -1,4 +1,5 @@ { "name": "@knit/path-join", - "version": "0.4.0" + "version": "0.4.0", + "main": "lib/js/pathJoin" } diff --git a/src/modules/@knit/read-pkg/ReadPkg.re b/src/modules/@knit/read-pkg/ReadPkg.re new file mode 100644 index 00000000..82738d9c --- /dev/null +++ b/src/modules/@knit/read-pkg/ReadPkg.re @@ -0,0 +1,8 @@ +type syncOptions = {normalize: bool}; + +external sync : Js.String.t => syncOptions => string = "" [@@bs.module "read-pkg"]; + +let readPkg dir_path package => { + let ret = sync (PathJoin.pathJoin dir_path package) {normalize: false}; + () +}; \ No newline at end of file diff --git a/src/modules/@knit/read-pkg/bsconfig.json b/src/modules/@knit/read-pkg/bsconfig.json new file mode 100644 index 00000000..a01bbeb0 --- /dev/null +++ b/src/modules/@knit/read-pkg/bsconfig.json @@ -0,0 +1,12 @@ +{ + "name": "@knit/read-pkg", + "sources": ".", + "package-specs": ["commonjs"], + "bsc-flags": [ + "-bs-cross-module-opt" + ], + "bs-dependencies": [ + "@knit/path-join" + ], + "generate-merlin": false +} diff --git a/src/modules/@knit/read-pkg/index.js b/src/modules/@knit/read-pkg/index.js index 1a804132..1f14e985 100644 --- a/src/modules/@knit/read-pkg/index.js +++ b/src/modules/@knit/read-pkg/index.js @@ -2,7 +2,7 @@ import rp from "read-pkg"; -import pathJoin from "@knit/path-join"; +import { pathJoin } from "@knit/path-join"; import type { TPkgJson } from "@knit/needle"; diff --git a/src/modules/@knit/read-pkg/lib/js/readPkg.js b/src/modules/@knit/read-pkg/lib/js/readPkg.js new file mode 100644 index 00000000..66b71c85 --- /dev/null +++ b/src/modules/@knit/read-pkg/lib/js/readPkg.js @@ -0,0 +1,13 @@ +// Generated by BUCKLESCRIPT VERSION 1.7.3, PLEASE EDIT WITH CARE +'use strict'; + +var PathJoin = require("@knit/path-join/lib/js/pathJoin.js"); +var ReadPkg = require("read-pkg"); + +function readPkg(dir_path, $$package) { + ReadPkg.sync(PathJoin.pathJoin(dir_path, $$package), /* record */[/* normalize : false */0]); + return /* () */0; +} + +exports.readPkg = readPkg; +/* PathJoin Not a pure module */