Skip to content

Commit

Permalink
fix: remove node_modules/. from ignored paths
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Nov 9, 2022
1 parent 1d8658d commit 21d1833
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 67 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ jobs:

- run: go install github.com/bazelbuild/buildtools/buildozer@latest
if: ${{ hashFiles(format('{0}/test.sh', matrix.folder)) != '' }}

- uses: pnpm/action-setup@v2
with:
version: '7.14.2'

- name: run ./test.sh
working-directory: ${{ matrix.folder }}
Expand All @@ -142,7 +146,7 @@ jobs:
run: |
cp -f $GITHUB_WORKSPACE/.github/workflows/ci.bazelrc .bazelrc.test
echo "build --config=${{ matrix.config }}" >> .bazelrc.test
echo "build --disk_cache=" >> .bazelrc.test
echo "build --disk_cache=/tmp/cache" >> .bazelrc.test
bazel clean
./test.sh
./test.sh
Expand All @@ -154,7 +158,7 @@ jobs:
run: |
cp -f $GITHUB_WORKSPACE/.github/workflows/ci.bazelrc .bazelrc.test
echo "build --config=${{ matrix.config }}" >> .bazelrc.test
echo "build --disk_cache=" >> .bazelrc.test
echo "build --disk_cache=/tmp/cache" >> .bazelrc.test
echo "build --noexperimental_allow_unresolved_symlinks" >> ".bazelrc.test"
bazel clean
./test.sh
Expand Down
90 changes: 52 additions & 38 deletions e2e/worker/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions e2e/worker/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

packages:
- 'transitive_closure/packages/*'
- 'transitive_closure'
19 changes: 19 additions & 0 deletions e2e/worker/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,25 @@ message "# Case 12: .tsbuildinfo file should be written when analysis cache is d
bazel build //composite || exit_with_message "Case 12: expected worker to build without errors."
bazel build //composite --action_env=ANALYSIS_CACHE_BUST=1 || exit_with_message "Case 12: expected worker to build without errors. (subsequent)"


message "# Case 13: should not ignore new transitive deps"

message="error TS2307: Cannot find module '@transitive_closure/b' or its corresponding type declarations."
bazel build //transitive_closure 2>&1 | grep "$message" || exit_with_message "Case 13: expected worker to report \"$message\""

lockfile_backup=$(mktemp)
cat pnpm-lock.yaml > $lockfile_backup
add_trap "cat $lockfile_backup > pnpm-lock.yaml"


tmp=$(mktemp -d)
jq '.pnpm.packageExtensions["@transitive_closure/a"].dependencies["@transitive_closure/b"] = "workspace:*"' package.json > "$tmp/package.json"
pnpm install --lockfile-only --dir "$tmp" --store-dir $(mktemp -d) --virtual-store-dir $(mktemp -d)
cat "$tmp/pnpm-lock.yaml" > pnpm-lock.yaml

bazel build //transitive_closure 2>&1 | grep "$message" && exit_with_message "Case 13: expected worker to not report \"$message\""


message "# Case X: Should dump traces"
bazel build //trace

Expand Down
14 changes: 14 additions & 0 deletions e2e/worker/transitive_closure/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

load("@npm//:defs.bzl", "npm_link_all_packages")
npm_link_all_packages(name = "node_modules")

ts_project(
name = "transitive_closure",
srcs = ["index.ts"],
deps = [
":node_modules/@transitive_closure/a",
],
tsconfig = "//:tsconfig",
tags = ["manual"]
)
3 changes: 3 additions & 0 deletions e2e/worker/transitive_closure/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { a } from '@transitive_closure/a';

console.log(a);
6 changes: 6 additions & 0 deletions e2e/worker/transitive_closure/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "transitive_closure",
"dependencies": {
"@transitive_closure/a": "workspace:*"
}
}
21 changes: 21 additions & 0 deletions e2e/worker/transitive_closure/packages/a/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_js//npm:defs.bzl", "npm_package")

load("@npm//:defs.bzl", "npm_link_all_packages")
npm_link_all_packages()

js_library(
name = "a_lib",
srcs = [
"index.d.ts",
"index.js",
]
)

npm_package(
name = "a",
srcs = [
":a_lib",
],
visibility = ["//visibility:public"],
)
3 changes: 3 additions & 0 deletions e2e/worker/transitive_closure/packages/a/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {b} from "@transitive_closure/b";

export const a: typeof b;
3 changes: 3 additions & 0 deletions e2e/worker/transitive_closure/packages/a/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const b = require("@transitive_closure/b");

module.exports.a = b.b;
4 changes: 4 additions & 0 deletions e2e/worker/transitive_closure/packages/a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@transitive_closure/a",
"dependencies": {}
}
22 changes: 22 additions & 0 deletions e2e/worker/transitive_closure/packages/b/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_js//npm:defs.bzl", "npm_package")

load("@npm//:defs.bzl", "npm_link_all_packages")
npm_link_all_packages()


js_library(
name = "b_lib",
srcs = [
"index.d.ts",
"index.js",
]
)

npm_package(
name = "b",
srcs = [
":b_lib",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions e2e/worker/transitive_closure/packages/b/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const b: string;
1 change: 1 addition & 0 deletions e2e/worker/transitive_closure/packages/b/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports.b = "1";
3 changes: 3 additions & 0 deletions e2e/worker/transitive_closure/packages/b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "@transitive_closure/b"
}
6 changes: 5 additions & 1 deletion e2e/worker/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"compilerOptions": {
"module": "ES2020",
"moduleResolution": "node"
"moduleResolution": "node",
"lib": [
"ES2015",
"DOM"
]
}
}
46 changes: 20 additions & 26 deletions ts/private/ts_project_worker.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
const fs = require('fs');
const path = require('path');
const v8 = require('v8');
const util = require("util")
const ts = require('typescript');
const worker = require('@bazel/worker');


// workaround for the issue introduced in https://github.com/microsoft/TypeScript/pull/42095
if (Array.isArray(ts.ignoredPaths)) {
ts.ignoredPaths = ts.ignoredPaths.filter(ignoredPath => ignoredPath != "/node_modules/.")
}


/** Constants */
const MNEMONIC = 'TsProject';

Expand Down Expand Up @@ -94,35 +100,23 @@ function createFilesystemTree(root, inputs) {
node = node[part];
}

// Digest is empty when the input is a symlink which we use as an indicator to limit number of realpath calls made.
// See: https://github.com/bazelbuild/bazel/pull/14002#issuecomment-977790796 for why it can be empty.
if (hash == null) {
const realpath = ts.sys.realpath(path.join(root, p));
const relative = path.relative(root, realpath);
if (relative != p) {
node[parts.base] = {
[Type]: TYPE.SYMLINK,
[Symlink]: relative
}
const absolutePath = path.join(root, p)
const stat = fs.lstatSync(absolutePath)

if (stat.isSymbolicLink()) {
const linkpath = fs.readlinkSync(absolutePath);
const absLinkpath = path.isAbsolute(linkpath) ? linkpath : path.resolve(path.dirname(absolutePath, linkpath))
const relative = path.relative(root, absLinkpath)
node[parts.base] = {
[Type]: TYPE.SYMLINK,
[Symlink]: relative
}
notifyWatchers(dirs, parts.base, TYPE.SYMLINK, EVENT_TYPE.ADDED);
} else if (parts.base) {
const new_node = {
node[parts.base] = {
[Type]: TYPE.FILE,
}
try {
const linkPath = path.join(root, p)
const readlink = fs.readlinkSync(linkPath);
const targetPath = path.isAbsolute(readlink) ? readlink : path.join(path.dirname(linkPath), readlink)
const relative = path.relative(root, targetPath);
if (relative != p) {
new_node[Type] = TYPE.SYMLINK
new_node[Symlink] = relative
}
} catch (e) { /* Can't determine if it's a symlink. move on */ }

node[parts.base] = new_node;
notifyWatchers(dirs, parts.base, new_node[Type], EVENT_TYPE.ADDED);
};
notifyWatchers(dirs, parts.base, TYPE.FILE, EVENT_TYPE.ADDED);
}
}

Expand Down

0 comments on commit 21d1833

Please sign in to comment.