Skip to content

Commit

Permalink
build(bazel): remaining AIO Bazel migration fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kormide authored and josephperrott committed Nov 22, 2022
1 parent a81d6d5 commit 903917b
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 55 deletions.
4 changes: 0 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,6 @@ jobs:
command: yarn --cwd aio test:ci
no_output_timeout: 20m

# TODO: run the following tests under bazel

# Check the bundle sizes.
- run: yarn --cwd aio payload-size

Expand All @@ -360,8 +358,6 @@ jobs:
command: yarn --cwd aio test-local:ci
no_output_timeout: 20m

# TODO: run the following tests under bazel

# Check the bundle sizes.
- run: yarn --cwd aio payload-size aio-local

Expand Down
9 changes: 5 additions & 4 deletions aio/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ E2E_DEPS = APPLICATION_DEPS + [
"//aio/tools:windows-chromium-path",
]

# Poll period for architect rules that watch for changes
ARCHITECT_POLL_MS = 1000

# Stamp npm_link targets for all dependencies that correspond to a
# first-party equivalent pacakge in angular.
link_local_packages(all_aio_deps = collections.uniq(APPLICATION_DEPS + TEST_DEPS + E2E_DEPS))
Expand All @@ -188,7 +191,6 @@ architect(
"--output-path=build-app",
],
chdir = "$(RULEDIR)",
configuration_env_vars = ["NG_BUILD_CACHE"],
data = [":application_files_bin"] + select({
":aio_local_deps": substitute_local_package_deps(APPLICATION_DEPS),
"//conditions:default": APPLICATION_DEPS,
Expand Down Expand Up @@ -247,7 +249,7 @@ aio_test(
args = [
"site:test",
"--watch",
"--poll=1000",
"--poll=%d" % ARCHITECT_POLL_MS,
],
data = TEST_DATA,
tags = [
Expand All @@ -265,7 +267,6 @@ architect_test(
"--port=0",
],
chdir = package_name(),
configuration_env_vars = ["NG_BUILD_CACHE"],
data = E2E_FILES + select({
":aio_local_deps": substitute_local_package_deps(E2E_DEPS),
"//conditions:default": E2E_DEPS,
Expand All @@ -285,7 +286,7 @@ architect(
args = [
"site:serve",
"--open",
"--poll=1000",
"--poll=%d" % ARCHITECT_POLL_MS,
"--live-reload",
"--watch",
],
Expand Down
1 change: 0 additions & 1 deletion aio/aio_targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def aio_test(name, data, args, **kwargs):
name = name,
args = args,
chdir = native.package_name(),
configuration_env_vars = ["NG_BUILD_CACHE"],
data = data,
env = {
"CHROME_BIN": "../$(CHROMIUM)",
Expand Down
7 changes: 6 additions & 1 deletion aio/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
"warnings": {
"typescriptMismatch": false
},
"analytics": false
"analytics": false,
"cache": {
// Disable build caching as the cache folder will just be dropped
// when run under Bazel sandboxed execution.
"enabled": false
}
},
"newProjectRoot": "projects",
"projects": {
Expand Down
1 change: 0 additions & 1 deletion aio/content/examples/examples.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ def docs_example(name, test = True, test_tags = [], test_exec_properties = {}, f
"//aio:aio_local_deps": LOCAL_PACKAGE_ARGS,
"//conditions:default": [],
}),
configuration_env_vars = ["NG_BUILD_CACHE"],
entry_point = "//aio/tools/examples:run-example-e2e.mjs",
env = {
"CHROME_BIN": "$(CHROMIUM)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ describe('View Encapsulation App', () => {
async function findShadowDomElement(shadowHostSelector: string, shadowElementSelector: string): Promise<WebElement> {
const shadowHost = browser.findElement(by.css(shadowHostSelector));
const shadowRoot: any = await browser.executeScript('return arguments[0].shadowRoot', shadowHost);
// TODO: Using this solution to find the shadow element after Chrome 97: https://stackoverflow.com/a/70611425.
// Is there a better way to do this?
// Using this solution to find the shadow element after Chrome 97: https://stackoverflow.com/a/70611425.
const rootKey = Object.keys(shadowRoot)[0];
const rootId = shadowRoot[rootKey];
return new WebElement(browser, rootId).findElement(by.css(shadowElementSelector));
Expand Down
2 changes: 1 addition & 1 deletion aio/scripts/local-workspace-status.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const pkgJsonPath = path.join(__dirname, '..', 'package.json');
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));

const aioAngularVersion = pkgJson.dependencies['@angular/core'].replace(/^[\^~]/, '') + "+locallySubstituted";
const aioAngularVersion = pkgJson.dependencies['@angular/core'].replace(/^[\^~]/, '') + "+forAIOLocalBuildToAvoidMismatch";

// Output the workspace status variable format to stdout so Bazel can read it
console.log(`\
Expand Down
11 changes: 4 additions & 7 deletions aio/scripts/run-with-local-server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,16 @@ async function main(args) {
'--quiet'
];
const lightserverProcess = sh.exec(lightserverCmd.join(' '), {async: true, silent: true});

const command = [
testScript,
...testScriptArgs
].join(' ').replace('LOCALHOST_URL', `http://localhost:${port}`);

sh.exec(command);
const returnCode = sh.exec(command).code;

await killProcess(lightserverProcess);

// TODO: On Windows something remains unresolved and node does not exit.
// It does not appear to be the lightserver process.
process.exit(0);
process.exit(returnCode);
}

(async() => await main(process.argv.slice(2)))();
Expand All @@ -63,4 +60,4 @@ function killProcess(childProcess) {
resolve();
});
});
}
}
67 changes: 35 additions & 32 deletions aio/tools/examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,58 +10,61 @@ exports_files([
"run-example-e2e.mjs",
])

EXAMPLE_BOILERPLATE_SRCS = [
"example-boilerplate.js",
"constants.js",
"//aio/tools/examples/shared",
"//aio/content/examples",
]

EXAMPLE_BOILERPLATE_DEPS = [
"@aio_npm//canonical-path",
"@aio_npm//fs-extra",
"@aio_npm//ignore",
"@aio_npm//shelljs",
"@aio_npm//yargs",
]
js_library(
name = "example-boilerplate-lib",
srcs = [
"constants.js",
"example-boilerplate.js",
],
deps = [
"//aio/content/examples",
"//aio/tools/examples/shared",
"@aio_npm//canonical-path",
"@aio_npm//fs-extra",
"@aio_npm//ignore",
"@aio_npm//shelljs",
"@aio_npm//yargs",
],
)

nodejs_binary(
name = "example-boilerplate",
data = EXAMPLE_BOILERPLATE_SRCS + EXAMPLE_BOILERPLATE_DEPS,
data = [":example-boilerplate-lib"],
entry_point = "example-boilerplate.js",
)

jasmine_node_test(
name = "example-boilerplate-test",
srcs = ["example-boilerplate.spec.js"],
deps = EXAMPLE_BOILERPLATE_SRCS + EXAMPLE_BOILERPLATE_DEPS,
deps = [":example-boilerplate-lib"],
)

CREATE_EXAMPLE_SRCS = [
"create-example.js",
"constants.js",
] + glob(["shared/**"])

CREATE_EXAMPLE_DEPS = [
"@aio_npm//@bazel/buildozer",
"@aio_npm//canonical-path",
"@aio_npm//fs-extra",
"@aio_npm//ignore",
"@aio_npm//shelljs",
"@aio_npm//yargs",
]
js_library(
name = "create-example-lib",
srcs = [
"create-example.js",
"constants.js",
] + glob(["shared/**"]),
deps = [
"@aio_npm//@bazel/buildozer",
"@aio_npm//canonical-path",
"@aio_npm//fs-extra",
"@aio_npm//ignore",
"@aio_npm//shelljs",
"@aio_npm//yargs",
],
)

nodejs_binary(
name = "create-example",
data = CREATE_EXAMPLE_SRCS + CREATE_EXAMPLE_DEPS,
data = [":create-example-lib"],
entry_point = "create-example.js",
)

jasmine_node_test(
name = "create-example-test",
srcs = ["create-example.spec.js"],
deps =
CREATE_EXAMPLE_SRCS + CREATE_EXAMPLE_DEPS,
deps = [":create-example-lib"],
)

js_library(
Expand Down
11 changes: 10 additions & 1 deletion aio/tools/examples/create-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,20 @@ if (require.main === module) {
* Create the directory and marker files for the new example.
*/
function createEmptyExample(exampleName, examplePath) {
validateExampleName(exampleName);
ensureExamplePath(examplePath);
writeExampleConfigFile(examplePath);
writeStackBlitzFile(exampleName, examplePath);
}

function validateExampleName(exampleName) {
if (/\s/.test(exampleName)) {
throw new Error(
`Unable to create example. The example name contains spaces: '${exampleName}'`
)
}
}

/**
* Ensure that the new example directory exists.
*/
Expand Down Expand Up @@ -144,4 +153,4 @@ exports.ensureExamplePath = ensureExamplePath;
exports.writeExampleConfigFile = writeExampleConfigFile;
exports.writeStackBlitzFile = writeStackBlitzFile;
exports.copyExampleFiles = copyExampleFiles;
exports.titleize = titleize;
exports.titleize = titleize;
6 changes: 6 additions & 0 deletions aio/tools/examples/create-example.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ describe('create-example tool', () => {
.toHaveBeenCalledWith(
path.resolve(`/path/to/foo-bar/${STACKBLITZ_CONFIG_FILENAME}`), jasmine.any(String));
});

it('should fail if the example name contains spaces', () => {
expect(() => createEmptyExample('foo bar', '/path/to/foo-bar')).toThrowError(
`Unable to create example. The example name contains spaces: 'foo bar'`
);
});
});

describe('ensureExamplePath', () => {
Expand Down
2 changes: 1 addition & 1 deletion aio/tools/transforms/cli-docs-package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function resolveCliSourcePath() {
return path;
}
// Case: bazel test, find in runfiles
return runfiles.resolveWorkspaceRelative('../angular_cli_src');
return runfiles.resolve('angular_cli_src');
}

// Define the dgeni package for generating the docs
Expand Down

0 comments on commit 903917b

Please sign in to comment.