Skip to content

Commit 1c0ebaf

Browse files
author
unennhexium
committed
Implement monorepo build example
1 parent d415e7d commit 1c0ebaf

13 files changed

+148
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.idea
33
node_modules
44
package-lock.json
5+
pnpm-lock.yaml
56
dist

index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ export const typescriptPaths = ({
6969
? resolvedFileName
7070
: resolvedFileName.replace(/\.tsx?$/i, '.js');
7171

72-
/* Do not use:
72+
/*
73+
* Do not use:
7374
* - path.dirname(tsConfigPath) -> using abs. path to <proj_root>/test/<tsconfig>
74-
* - __dirname -> using abs. path to compiled plugin files <proj_root>/dist
75-
* - process.env.PWD -> non cross-platform
76-
* instead of process.cwd() -> using abs. path to <proj_root>/<tsconfig>, that is correct
75+
* - __dirname -> using abs. path to compiled plugin files <proj_root>/dist
76+
* - process.env.PWD -> non cross-platform
77+
* instead of process.cwd() -> using abs. path to <proj_root>/<tsconfig>, that is correct
7778
*/
7879
const targetFileName = typeof compilerOptions.baseUrl === 'undefined'
7980
? join(outDir, relative(process.cwd(), processedFileName))

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
"files": [
88
"dist"
99
],
10+
"workspaces": [ "test" ],
1011
"scripts": {
12+
"test:mono-error": "npm run build:error --workspaces",
13+
"test:mono": "npm run build --workspaces",
1114
"test:wo-baseurl": "WO_BASEURL=true npm run test",
1215
"test": "npm run prepare && node test",
1316
"preversion": "npm test",

pnpm-lock.yaml

Lines changed: 73 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/bar/foo.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.bar = void 0;
4+
exports.bar = 'foo';

test/foo/bar-react.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.foo = void 0;
4+
exports.foo = 'bar';

test/foo/bar.d.ts

Whitespace-only changes.

test/foo/bar.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.foo = void 0;
4+
exports.foo = 'bar';

test/main.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.default = exports.bak = exports.bar = exports.baz = exports.foo = void 0;
4+
var _foobar_1 = require("@foobar");
5+
Object.defineProperty(exports, "foo", { enumerable: true, get: function () { return _foobar_1.foo; } });
6+
var _foobar_react_1 = require("@foobar-react");
7+
Object.defineProperty(exports, "baz", { enumerable: true, get: function () { return _foobar_react_1.foo; } });
8+
var foo_1 = require("@bar/foo");
9+
Object.defineProperty(exports, "bar", { enumerable: true, get: function () { return foo_1.bar; } });
10+
var foo_2 = require("bar/foo");
11+
Object.defineProperty(exports, "bak", { enumerable: true, get: function () { return foo_2.bar; } });
12+
var _js_1 = require("@js");
13+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return _js_1.default; } });

test/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { foo } from '@foobar'
2+
export { foo as baz } from '@foobar-react'
3+
export { bar } from '@bar/foo'
4+
export { bar as bak } from 'bar/foo'
5+
export { default } from '@js'

test/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "test",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"build": "tsc -p tsconfig-wo-baseurl-mono.json",
8+
"build:error": "tsc -p tsconfig-wo-baseurl.json",
9+
"prebuild": "rm -rf dist"
10+
},
11+
"keywords": [],
12+
"author": "",
13+
"license": "ISC"
14+
}

test/tsconfig-wo-baseurl-mono.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// comments should work
3+
"compilerOptions": {
4+
"paths": {
5+
"@foobar": ["./foo/bar"],
6+
"@foobar-react": ["./foo/bar-react"],
7+
"@bar/*": ["./bar/*"],
8+
"bar/*": ["./bar/*"],
9+
"@js": ["./js"],
10+
"$/*": ["./*"]
11+
},
12+
"jsx": "react",
13+
"outDir": "dist"
14+
},
15+
"files": [ "main.ts" ]
16+
}

test/tsconfig-wo-baseurl.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// comments should work
33
"compilerOptions": {
44
"paths": {
5-
"@foobar": ["test/foo/bar"],
6-
"@foobar-react": ["test/foo/bar-react"],
7-
"@bar/*": ["test/bar/*"],
8-
"bar/*": ["test/bar/*"],
9-
"@js": ["test/js"],
10-
"$/*": ["test/*"]
5+
"@foobar": ["./test/foo/bar"],
6+
"@foobar-react": ["./test/foo/bar-react"],
7+
"@bar/*": ["./test/bar/*"],
8+
"bar/*": ["./test/bar/*"],
9+
"@js": ["./test/js"],
10+
"$/*": ["./test/*"]
1111
}
1212
}
1313
}

0 commit comments

Comments
 (0)