-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
319 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on | ||
# projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what | ||
# rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules) | ||
hoist=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
load("@aspect_rules_js//js:defs.bzl", "js_test") | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
|
||
npm_link_all_packages() | ||
|
||
js_test( | ||
name = "runfiles", | ||
data = [ | ||
"test_fixture.md", | ||
"test_fixture.md.generated_file_suffix", | ||
":node_modules/@bazel/runfiles", | ||
], | ||
entry_point = "test.js", | ||
) | ||
|
||
# Path of file must start similar to `test_fixture.md` in order to regression-test a | ||
# scenario where the runfile resolution would accidentally resolve the path to | ||
# `test_fixture.md` through a runfile manifest entry that starts similarly. | ||
genrule( | ||
name = "gen-data", | ||
outs = ["test_fixture.md.generated_file_suffix"], | ||
cmd = """echo "Generated" > $@""", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module(name = "e2e_runfiles") | ||
|
||
bazel_dep(name = "aspect_rules_js", version = "0.0.0", dev_dependency = True) | ||
local_path_override( | ||
module_name = "aspect_rules_js", | ||
path = "../..", | ||
) | ||
|
||
bazel_dep(name = "aspect_bazel_lib", version = "2.7.7", dev_dependency = True) | ||
|
||
npm = use_extension( | ||
"@aspect_rules_js//npm:extensions.bzl", | ||
"npm", | ||
dev_dependency = True, | ||
) | ||
npm.npm_translate_lock( | ||
name = "npm", | ||
npmrc = "//:.npmrc", | ||
pnpm_lock = "//:pnpm-lock.yaml", | ||
verify_node_modules_ignored = "//:.bazelignore", | ||
) | ||
use_repo(npm, "npm") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# The presence of this file causes WORKSPACE to be ignored when bzlmod is enabled. | ||
# See https://docs.google.com/document/d/1JtXIVnXyFZ4bmbiBCr5gsTH4-opZAFf5DMMb-54kES0/edit#heading=h.y054fjub9max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@examples/runfiles", | ||
"private": true, | ||
"dependencies": { | ||
"@bazel/runfiles": "^6.3.0" | ||
}, | ||
"pnpm": { | ||
"onlyBuiltDependencies": [] | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
packages: | ||
- '.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const { join, dirname } = require('path') | ||
const { Runfiles } = require('@bazel/runfiles') | ||
|
||
function describe(name, fn) { | ||
console.log(name) | ||
fn() | ||
} | ||
function it(name, fn) { | ||
console.log(` ${name}`) | ||
fn() | ||
} | ||
|
||
function assert(t, msg) { | ||
if (!t) { | ||
throw new Error(msg) | ||
} | ||
} | ||
|
||
const runfiles = new Runfiles(process.env) | ||
|
||
describe('runfile resolution', () => { | ||
it('should properly resolve the files with the module(name)', () => { | ||
const testFixturePath = runfiles.resolve('e2e_runfiles/test_fixture.md') | ||
const expectedPath = join(__dirname, 'test_fixture.md') | ||
|
||
assert( | ||
normalizePath(testFixturePath) == normalizePath(expectedPath), | ||
`Expected the test fixture to be resolved next to the spec source file: ${testFixturePath} vs ${expectedPath}` | ||
) | ||
}) | ||
|
||
it('should properly resolve with forward slashes', () => { | ||
const testFixturePath = runfiles.resolve( | ||
'e2e_runfiles\\test_fixture.md' | ||
) | ||
const expectedPath = join(__dirname, 'test_fixture.md') | ||
|
||
assert( | ||
normalizePath(testFixturePath) == normalizePath(expectedPath), | ||
`Expected the test fixture to be resolved next to the spec source file: ${testFixturePath} vs ${expectedPath}` | ||
) | ||
}) | ||
|
||
it('should properly resolve with the __main__ module alias', () => { | ||
const testFixturePath = runfiles.resolve('__main__/test_fixture.md') | ||
const expectedPath = join(__dirname, 'test_fixture.md') | ||
|
||
assert( | ||
normalizePath(testFixturePath) == normalizePath(expectedPath), | ||
`Expected the test fixture to be resolved next to the spec source file: ${testFixturePath} vs ${expectedPath}` | ||
) | ||
}) | ||
|
||
it('should properly resolve a runfile within a direct module dependency', () => { | ||
const fsPatchPath = runfiles.resolve( | ||
'aspect_rules_js/js/private/node-patches/fs.cjs' | ||
) | ||
|
||
assert(!!fsPatchPath, `Expected to find fs patches`) | ||
assert( | ||
fsPatchPath.indexOf('/aspect_rules_js/') == -1, | ||
`Expected to find fs patches in a resolved bzlmod directory` | ||
) | ||
}) | ||
}) | ||
|
||
/** | ||
* Normalizes the delimiters within the specified path. This is useful for test assertions | ||
* where paths might be computed using different path delimiters. | ||
*/ | ||
function normalizePath(value) { | ||
return value.replace(/\\/g, '/') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a file part of the sources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
load("@aspect_rules_js//js:defs.bzl", "js_test") | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
|
||
npm_link_all_packages() | ||
|
||
js_test( | ||
name = "runfiles", | ||
data = [ | ||
"test_fixture.md", | ||
"test_fixture.md.generated_file_suffix", | ||
":node_modules/@bazel/runfiles", | ||
], | ||
entry_point = "test.js", | ||
) | ||
|
||
# Path of file must start similar to `test_fixture.md` in order to regression-test a | ||
# scenario where the runfile resolution would accidentally resolve the path to | ||
# `test_fixture.md` through a runfile manifest entry that starts similarly. | ||
genrule( | ||
name = "gen-data", | ||
outs = ["test_fixture.md.generated_file_suffix"], | ||
cmd = """echo "Generated" > $@""", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "@examples/runfiles", | ||
"private": true, | ||
"dependencies": { | ||
"@bazel/runfiles": "^6.3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
const { join, dirname } = require('path') | ||
const { Runfiles } = require('@bazel/runfiles') | ||
|
||
function describe(name, fn) { | ||
console.log(name) | ||
fn() | ||
} | ||
function it(name, fn) { | ||
console.log(` ${name}`) | ||
fn() | ||
} | ||
|
||
function assert(t, msg) { | ||
if (!t) { | ||
throw new Error(msg) | ||
} | ||
} | ||
|
||
const runfiles = new Runfiles(process.env) | ||
|
||
describe('runfile resolution', () => { | ||
it('should properly resolve the files with the module(name)', () => { | ||
const testFixturePath = runfiles.resolve( | ||
'aspect_rules_js/examples/runfiles/test_fixture.md' | ||
) | ||
const expectedPath = join(__dirname, 'test_fixture.md') | ||
|
||
assert( | ||
normalizePath(testFixturePath) == normalizePath(expectedPath), | ||
`Expected the test fixture to be resolved next to the spec source file: ${testFixturePath} vs ${expectedPath}` | ||
) | ||
}) | ||
|
||
it('should properly resolve with forward slashes', () => { | ||
const testFixturePath = runfiles.resolve( | ||
'aspect_rules_js\\examples\\runfiles\\test_fixture.md' | ||
) | ||
const expectedPath = join(__dirname, 'test_fixture.md') | ||
|
||
assert( | ||
normalizePath(testFixturePath) == normalizePath(expectedPath), | ||
`Expected the test fixture to be resolved next to the spec source file: ${testFixturePath} vs ${expectedPath}` | ||
) | ||
}) | ||
|
||
it('should properly resolve with the __main__ module alias', () => { | ||
const testFixturePath = runfiles.resolve( | ||
'__main__/examples/runfiles/test_fixture.md' | ||
) | ||
const expectedPath = join(__dirname, 'test_fixture.md') | ||
|
||
assert( | ||
normalizePath(testFixturePath) == normalizePath(expectedPath), | ||
`Expected the test fixture to be resolved next to the spec source file: ${testFixturePath} vs ${expectedPath}` | ||
) | ||
}) | ||
|
||
it('should properly resolve a subdirectory of a runfile', () => { | ||
const packagePath = runfiles.resolve('aspect_rules_js/examples') | ||
// Alternate with trailing slash | ||
const packagePath2 = runfiles.resolve('aspect_rules_js/examples/') | ||
const expectedPath = dirname( | ||
dirname( | ||
runfiles.resolve( | ||
'aspect_rules_js/examples/runfiles/test_fixture.md.generated_file_suffix' | ||
) | ||
) | ||
) | ||
|
||
assert( | ||
normalizePath(packagePath) == normalizePath(expectedPath), | ||
`Expected to resolve a subdirectory of a runfile: ${packagePath} vs ${expectedPath}` | ||
) | ||
assert( | ||
normalizePath(packagePath2) == normalizePath(expectedPath), | ||
`Expected to resolve a subdirectory of a runfile: ${packagePath2} vs ${expectedPath}` | ||
) | ||
}) | ||
|
||
it('should properly resolve the workspace root of a runfile', () => { | ||
const packagePath = runfiles.resolve('aspect_rules_js') | ||
// Alternate with trailing slash | ||
const packagePath2 = runfiles.resolve('aspect_rules_js/') | ||
const expectedPath = dirname( | ||
dirname( | ||
dirname( | ||
runfiles.resolve( | ||
'aspect_rules_js/examples/runfiles/test_fixture.md.generated_file_suffix' | ||
) | ||
) | ||
) | ||
) | ||
|
||
assert( | ||
normalizePath(packagePath) == normalizePath(expectedPath), | ||
`Expected to resolve the workspace root of a runfile: ${packagePath} vs ${expectedPath}` | ||
) | ||
assert( | ||
normalizePath(packagePath2) == normalizePath(expectedPath), | ||
`Expected to resolve the workspace root of a runfile: ${packagePath2} vs ${expectedPath}` | ||
) | ||
}) | ||
}) | ||
|
||
/** | ||
* Normalizes the delimiters within the specified path. This is useful for test assertions | ||
* where paths might be computed using different path delimiters. | ||
*/ | ||
function normalizePath(value) { | ||
return value.replace(/\\/g, '/') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a file part of the sources |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.