From 86aed90ab2167395948605c1020627ab68c42149 Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Sun, 13 May 2018 07:00:18 -0700 Subject: [PATCH] Update package doc --- PACKAGES.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/PACKAGES.md b/PACKAGES.md index 64b8d984..df5b06d4 100644 --- a/PACKAGES.md +++ b/PACKAGES.md @@ -10,8 +10,12 @@ `quicktype-typescript-input` has to work both as its own package, depending on the `quicktype-core` package, as well as part of `quicktype`, referring to the files in the local `src/quicktype-core` directory. -In addition, since `quicktype-typescript-input` depends on `quicktype-core`, we would have first build `quicktype-core`, publish it, and then build `quicktype-typescript-input`, depending on the just published `quicktype-core`. This is bad for development, since we couldn't do modifications to both packages without publishing, if we want to test independent of the `quicktype` package. The same goes for CI. Therefore, it has to build as a package depending on the local `build/quicktype-core` package, but has to be published depending on the proper `quicktype-core` NPM package. We solve this the following way: +In addition, since `quicktype-typescript-input` depends on `quicktype-core`, we would have to first build `quicktype-core`, publish it, and then build `quicktype-typescript-input`, depending on the just published `quicktype-core`. This is bad for development, since we couldn't do modifications to both packages without publishing, if we want to test independent of the `quicktype` package. The same goes for CI. Therefore, it has to build as a package depending on the local `build/quicktype-core` package, but has to be published depending on the proper `quicktype-core` NPM package. We solve this the following way: -* `quicktype-typescript-input` imports from `"quicktype-core"` as if it were a package dependency. That means its `.js` files won't have to be modified for packaging of `quicktype-typescript-input`, but they will have to be rewritten to refer to `"../quicktype-core"` when building as part of the `quicktype` package. This rewriting happens in `script/build.ts`. +* All packages, including `quicktype-typescript-input`, import files with local paths, such as `"../quicktype-core"`. This seems the only way to make VSCode's TypeScript integration, as well as `ts-node` happy. Unfortunately, since local paths can's use `tsc`'s path mapping, we have to rewrite those paths _before_ compiling, which is done in `build/quicktype-typescript-input/build.ts`: it copies all the sources, rewrites them, compiles, and then deletes the copied sources again. -* Its `package.json` will have to refer to either the local `quicktype-core` package, or the NPM one. We do this by having a build script `build/quicktype-typescript-input/build.ts` that replaces the dependency with the right one for the job. +* Depending on whether we build `quicktype-typescript-input`, or publish it, its `package.json` will have to refer to either the local `quicktype-core` package, or the NPM one. This is also done by the build script, which replaces the dependency with the right one for the job. + +## Issues + +Module resolution in Node is such that if a package is not found in the local `node_modules` directory, it goes up the directory hierarchy and tries every `node_modules` directory it finds. We have a `node_modules` in the root directory of our repo, so a subpackage build will fall back to that if it can't find a package locally. The main consequence of that seems to be that the build won't catch missing dependencies in those packages if they're present in the root package. Moving the root `package.json` to `build/quicktype` screws with lots of tooling.