Skip to content

Commit 44a21c8

Browse files
committed
Initial set of files with non-scoped packages
0 parents  commit 44a21c8

File tree

20 files changed

+3188
-0
lines changed

20 files changed

+3188
-0
lines changed

.bazelignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.git
2+
.vscode
3+
node_modules

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bazel-*
2+
node_modules

BUILD

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
2+
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
3+
load("@npm//:defs.bzl", "npm_link_all_packages")
4+
5+
npm_link_all_packages(
6+
name = "node_modules"
7+
)
8+
9+
npm_link_package(
10+
name = "node_modules/button",
11+
src = "//packages/button:package"
12+
)
13+
14+
npm_link_package(
15+
name = "node_modules/button-with-description",
16+
src = "//packages/button-with-description:package"
17+
)
18+
19+
npm_link_package(
20+
name = "node_modules/error-message",
21+
src = "//packages/error-message:package"
22+
)
23+
24+
ts_config(
25+
name = "tsconfig",
26+
visibility = ["//visibility:public"],
27+
src = "tsconfig.json",
28+
)

WORKSPACE

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
3+
################################################
4+
# bazel_skylib
5+
################################################
6+
7+
http_archive(
8+
name = "bazel_skylib",
9+
sha256 = "66ffd9315665bfaafc96b52278f57c7e2dd09f5ede279ea6d39b2be471e7e3aa",
10+
urls = [
11+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz",
12+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz",
13+
],
14+
)
15+
16+
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
17+
bazel_skylib_workspace()
18+
19+
################################################
20+
# rules_js
21+
################################################
22+
23+
http_archive(
24+
name = "aspect_rules_js",
25+
sha256 = "7b2a4d1d264e105eae49a27e2e78065b23e2e45724df2251eacdd317e95bfdfd",
26+
strip_prefix = "rules_js-1.31.0",
27+
url = "https://github.com/aspect-build/rules_js/releases/download/v1.31.0/rules_js-v1.31.0.tar.gz",
28+
)
29+
30+
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
31+
rules_js_dependencies()
32+
33+
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
34+
nodejs_register_toolchains(
35+
name = "nodejs",
36+
node_version = DEFAULT_NODE_VERSION,
37+
)
38+
39+
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")
40+
npm_translate_lock(
41+
name = "npm",
42+
pnpm_lock = "//:pnpm-lock.yaml",
43+
verify_node_modules_ignored = "//:.bazelignore",
44+
)
45+
46+
load("@npm//:repositories.bzl", "npm_repositories")
47+
npm_repositories()
48+
49+
################################################
50+
# rules_ts
51+
################################################
52+
53+
http_archive(
54+
name = "aspect_rules_ts",
55+
sha256 = "4c3f34fff9f96ffc9c26635d8235a32a23a6797324486c7d23c1dfa477e8b451",
56+
strip_prefix = "rules_ts-1.4.5",
57+
url = "https://github.com/aspect-build/rules_ts/releases/download/v1.4.5/rules_ts-v1.4.5.tar.gz",
58+
)
59+
60+
load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")
61+
rules_ts_dependencies(
62+
# This keeps the TypeScript version in-sync with the editor, which is typically best.
63+
ts_version_from = "//:package.json",
64+
)
65+
66+
################################################
67+
# rules_webpack
68+
################################################
69+
70+
http_archive(
71+
name = "aspect_rules_webpack",
72+
sha256 = "78d05d9e87ee804accca80a4fec98a66f146b6058e915eae3d97190397ad12df",
73+
strip_prefix = "rules_webpack-0.12.0",
74+
url = "https://github.com/aspect-build/rules_webpack/releases/download/v0.12.0/rules_webpack-v0.12.0.tar.gz",
75+
)
76+
77+
load("@aspect_rules_webpack//webpack:dependencies.bzl", "rules_webpack_dependencies")
78+
rules_webpack_dependencies()

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "transitive-dep-test",
3+
"description": "Testing transitive dependencies with Webpack where two separate node_modules trees are brought into the Webpack compilation",
4+
"version": "0.0.0",
5+
"private": true,
6+
"dependencies": {
7+
"@types/react": "18.2.18",
8+
"@types/react-dom": "^18.2.7",
9+
"html-webpack-plugin": "^5.5.3",
10+
"react": "18.2.0",
11+
"react-dom": "^18.2.0",
12+
"ts-loader": "^9.4.4",
13+
"typescript": "5.1.6",
14+
"webpack": "^5.88.2",
15+
"webpack-bundle-analyzer": "^4.9.0",
16+
"webpack-cli": "^5.1.4",
17+
"webpack-dev-server": "^4.15.1"
18+
}
19+
}

packages/app/BUILD

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
load("@aspect_rules_webpack//webpack:defs.bzl", "webpack_devserver")
2+
3+
webpack_devserver(
4+
name = "serve",
5+
node_modules = "//:node_modules",
6+
chdir = package_name(),
7+
entry_point = "src/app.tsx",
8+
data = [
9+
"tsconfig.json",
10+
"//:tsconfig",
11+
12+
# 1st-party dependency
13+
"//:node_modules/error-message",
14+
15+
# 3rd-party dependencies
16+
"//:node_modules/@types/react",
17+
"//:node_modules/@types/react-dom",
18+
"//:node_modules/html-webpack-plugin",
19+
"//:node_modules/react",
20+
"//:node_modules/react-dom",
21+
"//:node_modules/ts-loader",
22+
"//:node_modules/webpack-bundle-analyzer",
23+
],
24+
webpack_config = "webpack.config.js",
25+
args = [
26+
'--open',
27+
],
28+
)

packages/app/src/app.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { useState } from 'react';
2+
import { createRoot } from 'react-dom/client';
3+
import { ErrorMessage } from 'error-message'; // 1st party package
4+
5+
const App: React.FC = () => {
6+
// trigger multiple copies of react issue
7+
useState(3);
8+
9+
return <>
10+
<div><ErrorMessage message="Something went wrong!" /></div>
11+
</>;
12+
}
13+
14+
// -----------------
15+
16+
const reactRootEl = document.createElement('div');
17+
document.body.appendChild(reactRootEl);
18+
19+
const root = createRoot(reactRootEl);
20+
root.render(<App />);

packages/app/tsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"paths": {
5+
"button": ["../button/src"],
6+
"button-with-description": ["../button-with-description/src"],
7+
"error-message": ["../error-message/src"],
8+
}
9+
},
10+
"include": ["src/**/*"]
11+
}

packages/app/webpack.config.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const HtmlWebpackPlugin = require('html-webpack-plugin');
2+
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
3+
4+
console.log(`Running webpack in directory: '${process.cwd()}'`);
5+
6+
module.exports = {
7+
resolve: {
8+
extensions: ['.tsx', '.ts', '.js'],
9+
symlinks: true,
10+
},
11+
module: {
12+
rules: [
13+
{
14+
test: /\.tsx?$/,
15+
exclude: /node_modules/,
16+
use: [
17+
{ loader: 'ts-loader', options: { transpileOnly: true } },
18+
],
19+
}
20+
],
21+
},
22+
plugins: [
23+
new HtmlWebpackPlugin(),
24+
new BundleAnalyzerPlugin({
25+
openAnalyzer: true
26+
}),
27+
]
28+
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
load("@aspect_rules_js//js:defs.bzl", "js_library")
2+
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
3+
load("@aspect_rules_ts//ts:defs.bzl", "ts_project", "ts_config")
4+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
5+
6+
# Convenience alias for bazel build
7+
alias(
8+
name = "button-with-description",
9+
actual = ":package"
10+
)
11+
12+
npm_package(
13+
name = "package",
14+
visibility = ["//visibility:public"],
15+
package = "button-with-description",
16+
srcs = [":library"],
17+
out = "package",
18+
include_runfiles = False,
19+
20+
# Don't include .ts source files and tsconfig.json in package
21+
exclude_srcs_patterns = [
22+
"src/**",
23+
]
24+
)
25+
26+
js_library(
27+
name = "library",
28+
srcs = [
29+
":package_json",
30+
],
31+
deps = [
32+
":js"
33+
]
34+
)
35+
36+
write_file(
37+
name = "package_json",
38+
out = "package.json",
39+
content = [
40+
'{',
41+
' "name": "button-with-description",',
42+
' "version": "0.0.0",',
43+
' "main": "./dist/index.js",',
44+
' "module": "./dist/index.js",',
45+
' "typings": "./dist/index.d.ts",',
46+
' "sideEffects": false',
47+
'}',
48+
]
49+
)
50+
51+
ts_project(
52+
name = "js",
53+
tsconfig = ":tsconfig",
54+
root_dir = "src",
55+
out_dir = "dist",
56+
srcs = [
57+
"src/index.tsx"
58+
],
59+
deps = [
60+
"//:node_modules/button", # Our custom package
61+
"//:node_modules/@types/react",
62+
"//:node_modules/react",
63+
],
64+
declaration = True,
65+
supports_workers = False,
66+
)
67+
68+
ts_config(
69+
name = "tsconfig",
70+
src = "tsconfig.json",
71+
deps = ["//:tsconfig"],
72+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { FC, useState } from 'react';
2+
import { Button } from 'button'; // 1st-party package
3+
4+
/**
5+
* Simple component which displays a message and a button
6+
*/
7+
export const ButtonWithDescription: FC<ButtonWithDescriptionProps> = props => {
8+
// trigger multiple copies of react issue
9+
useState(2);
10+
11+
return (
12+
<div>
13+
{props.description}: <Button>My Button</Button>
14+
</div>
15+
);
16+
};
17+
18+
interface ButtonWithDescriptionProps {
19+
description: string;
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"paths": {
5+
"button": ["../button/src"]
6+
}
7+
},
8+
"include": ["src/**/*"]
9+
}

0 commit comments

Comments
 (0)