refactor: replace critters with beasties

The Critters project has been transferred to the Nuxt team, who will now manage its development and has been renamed to Beasties.

See: https://github.com/danielroe/beasties
This commit is contained in:
Alan Agius 2024-10-28 07:47:44 +00:00 committed by Alan Agius
parent 1fc8fdea2c
commit 15677d0cb7
19 changed files with 313 additions and 152 deletions

View File

@ -124,12 +124,12 @@
"ansi-colors": "4.1.3",
"autoprefixer": "10.4.20",
"babel-loader": "9.2.1",
"beasties": "0.1.0",
"browser-sync": "3.0.3",
"browserslist": "^4.21.5",
"buffer": "6.0.3",
"chokidar": "4.0.1",
"copy-webpack-plugin": "12.0.2",
"critters": "0.0.25",
"css-loader": "7.1.2",
"debug": "^4.1.1",
"esbuild": "0.24.0",

View File

@ -78,8 +78,8 @@ ts_library(
"@npm//@types/semver",
"@npm//@types/watchpack",
"@npm//@vitejs/plugin-basic-ssl",
"@npm//beasties",
"@npm//browserslist",
"@npm//critters",
"@npm//esbuild",
"@npm//esbuild-wasm",
"@npm//fast-glob",

View File

@ -26,8 +26,8 @@
"@babel/plugin-syntax-import-attributes": "7.25.9",
"@inquirer/confirm": "5.0.0",
"@vitejs/plugin-basic-ssl": "1.1.0",
"beasties": "0.1.0",
"browserslist": "^4.23.0",
"critters": "0.0.25",
"esbuild": "0.24.0",
"fast-glob": "3.3.2",
"https-proxy-agent": "7.0.5",

View File

@ -50,9 +50,9 @@ export function checkCommonJSModules(
allowedRequests.add('xhr2');
// Packages used by @angular/ssr.
// While critters is ESM it has a number of direct and transtive CJS deps.
// While beasties is ESM it has a number of direct and transtive CJS deps.
allowedRequests.add('express');
allowedRequests.add('critters');
allowedRequests.add('beasties');
// Find all entry points that contain code (JS/TS)
const files: string[] = [];

View File

@ -74,7 +74,7 @@ export function createGlobalStylesBundleOptions(
);
// Keep special CSS comments `/*! comment */` in place when `removeSpecialComments` is disabled.
// These comments are special for a number of CSS tools such as Critters and PurgeCSS.
// These comments are special for a number of CSS tools such as Beasties and PurgeCSS.
buildOptions.legalComments = optimizationOptions.styles?.removeSpecialComments
? 'none'
: 'inline';

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/
// The `bundled_critters` causes issues with module mappings in Bazel,
// The `bundled_beasties` causes issues with module mappings in Bazel,
// leading to unexpected behavior with esbuild. Specifically, the problem occurs
// when esbuild resolves to a different module or version than expected, due to
// how Bazel handles module mappings.

View File

@ -6,16 +6,16 @@
* found in the LICENSE file at https://angular.dev/license
*/
import Critters from 'critters';
import Beasties from 'beasties';
import { readFile } from 'node:fs/promises';
/**
* Pattern used to extract the media query set by Critters in an `onload` handler.
* Pattern used to extract the media query set by Beasties in an `onload` handler.
*/
const MEDIA_SET_HANDLER_PATTERN = /^this\.media=["'](.*)["'];?$/;
/**
* Name of the attribute used to save the Critters media query so it can be re-assigned on load.
* Name of the attribute used to save the Beasties media query so it can be re-assigned on load.
*/
const CSP_MEDIA_ATTR = 'ngCspMedia';
@ -58,8 +58,7 @@ const LINK_LOAD_SCRIPT_CONTENT = `
};
documentElement.addEventListener('load', listener, true);
})();
`.trim();
})();`;
export interface InlineCriticalCssProcessOptions {
outputPath: string;
@ -98,14 +97,14 @@ interface PartialDocument {
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
// We use Typescript declaration merging because `embedLinkedStylesheet` it's not declared in
// the `Critters` types which means that we can't call the `super` implementation.
interface CrittersBase {
// the `Beasties` types which means that we can't call the `super` implementation.
interface BeastiesBase {
embedLinkedStylesheet(link: PartialHTMLElement, document: PartialDocument): Promise<unknown>;
}
class CrittersBase extends Critters {}
class BeastiesBase extends Beasties {}
/* eslint-enable @typescript-eslint/no-unsafe-declaration-merging */
class CrittersExtended extends CrittersBase {
class BeastiesExtended extends BeastiesBase {
readonly warnings: string[] = [];
readonly errors: string[] = [];
private addedCspScriptsDocuments = new WeakSet<PartialDocument>();
@ -143,7 +142,7 @@ class CrittersExtended extends CrittersBase {
}
/**
* Override of the Critters `embedLinkedStylesheet` method
* Override of the Beasties `embedLinkedStylesheet` method
* that makes it work with Angular's CSP APIs.
*/
override async embedLinkedStylesheet(
@ -165,19 +164,19 @@ class CrittersExtended extends CrittersBase {
const cspNonce = this.findCspNonce(document);
if (cspNonce) {
const crittersMedia = link.getAttribute('onload')?.match(MEDIA_SET_HANDLER_PATTERN);
const beastiesMedia = link.getAttribute('onload')?.match(MEDIA_SET_HANDLER_PATTERN);
if (crittersMedia) {
// If there's a Critters-generated `onload` handler and the file has an Angular CSP nonce,
if (beastiesMedia) {
// If there's a Beasties-generated `onload` handler and the file has an Angular CSP nonce,
// we have to remove the handler, because it's incompatible with CSP. We save the value
// in a different attribute and we generate a script tag with the nonce that uses
// `addEventListener` to apply the media query instead.
link.removeAttribute('onload');
link.setAttribute(CSP_MEDIA_ATTR, crittersMedia[1]);
link.setAttribute(CSP_MEDIA_ATTR, beastiesMedia[1]);
this.conditionallyInsertCspLoadingScript(document, cspNonce, link);
}
// Ideally we would hook in at the time Critters inserts the `style` tags, but there isn't
// Ideally we would hook in at the time Beasties inserts the `style` tags, but there isn't
// a way of doing that at the moment so we fall back to doing it any time a `link` tag is
// inserted. We mitigate it by only iterating the direct children of the `<head>` which
// should be pretty shallow.
@ -200,7 +199,7 @@ class CrittersExtended extends CrittersBase {
return this.documentNonces.get(document)!;
}
// HTML attribute are case-insensitive, but the parser used by Critters is case-sensitive.
// HTML attribute are case-insensitive, but the parser used by Beasties is case-sensitive.
const nonceElement = document.querySelector('[ngCspNonce], [ngcspnonce]');
const cspNonce =
nonceElement?.getAttribute('ngCspNonce') || nonceElement?.getAttribute('ngcspnonce') || null;
@ -240,16 +239,16 @@ export class InlineCriticalCssProcessor {
html: string,
options: InlineCriticalCssProcessOptions,
): Promise<{ content: string; warnings: string[]; errors: string[] }> {
const critters = new CrittersExtended({ ...this.options, ...options });
const content = await critters.process(html);
const beasties = new BeastiesExtended({ ...this.options, ...options });
const content = await beasties.process(html);
return {
// Clean up value from value less attributes.
// This is caused because parse5 always requires attributes to have a string value.
// nomodule="" defer="" -> nomodule defer.
content: content.replace(/(\s(?:defer|nomodule))=""/g, '$1'),
errors: critters.errors,
warnings: critters.warnings,
errors: beasties.errors,
warnings: beasties.warnings,
};
}
}

View File

@ -19,7 +19,7 @@ ts_library(
module_name = "@angular/ssr",
tsconfig = "//:tsconfig-build-ng",
deps = [
"//packages/angular/ssr/third_party/critters:bundled_critters_lib",
"//packages/angular/ssr/third_party/beasties:bundled_beasties_lib",
"//packages/angular/ssr/tokens",
"@npm//@angular/common",
"@npm//@angular/core",
@ -34,13 +34,13 @@ ng_package(
package_name = "@angular/ssr",
srcs = [
":package.json",
"//packages/angular/ssr/third_party/critters:bundled_critters_lib",
"//packages/angular/ssr/third_party/beasties:bundled_beasties_lib",
],
externals = [
"@angular/ssr",
"@angular/ssr/node",
"@angular/ssr/tokens",
"../../third_party/critters",
"../../third_party/beasties",
],
nested_packages = [
"//packages/angular/ssr/schematics:npm_package",

View File

@ -13,7 +13,7 @@ export class CommonEngineInlineCriticalCssProcessor {
private readonly resourceCache = new Map<string, string>();
async process(html: string, outputPath: string | undefined): Promise<string> {
const critters = new InlineCriticalCssProcessor(async (path) => {
const beasties = new InlineCriticalCssProcessor(async (path) => {
let resourceContent = this.resourceCache.get(path);
if (resourceContent === undefined) {
resourceContent = await readFile(path, 'utf-8');
@ -23,6 +23,6 @@ export class CommonEngineInlineCriticalCssProcessor {
return resourceContent;
}, outputPath);
return critters.process(html);
return beasties.process(html);
}
}

View File

@ -6,15 +6,15 @@
* found in the LICENSE file at https://angular.dev/license
*/
import Critters from '../../third_party/critters';
import Beasties from '../../third_party/beasties';
/**
* Pattern used to extract the media query set by Critters in an `onload` handler.
* Pattern used to extract the media query set by Beasties in an `onload` handler.
*/
const MEDIA_SET_HANDLER_PATTERN = /^this\.media=["'](.*)["'];?$/;
/**
* Name of the attribute used to save the Critters media query so it can be re-assigned on load.
* Name of the attribute used to save the Beasties media query so it can be re-assigned on load.
*/
const CSP_MEDIA_ATTR = 'ngCspMedia';
@ -57,8 +57,7 @@ const LINK_LOAD_SCRIPT_CONTENT = `
};
documentElement.addEventListener('load', listener, true);
})();
`.trim();
})();`;
/** Partial representation of an `HTMLElement`. */
interface PartialHTMLElement {
@ -87,14 +86,14 @@ interface PartialDocument {
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
// We use Typescript declaration merging because `embedLinkedStylesheet` it's not declared in
// the `Critters` types which means that we can't call the `super` implementation.
interface CrittersBase {
// the `Beasties` types which means that we can't call the `super` implementation.
interface BeastiesBase {
embedLinkedStylesheet(link: PartialHTMLElement, document: PartialDocument): Promise<unknown>;
}
class CrittersBase extends Critters {}
class BeastiesBase extends Beasties {}
/* eslint-enable @typescript-eslint/no-unsafe-declaration-merging */
export class InlineCriticalCssProcessor extends CrittersBase {
export class InlineCriticalCssProcessor extends BeastiesBase {
private addedCspScriptsDocuments = new WeakSet<PartialDocument>();
private documentNonces = new WeakMap<PartialDocument, string | null>();
@ -126,7 +125,7 @@ export class InlineCriticalCssProcessor extends CrittersBase {
}
/**
* Override of the Critters `embedLinkedStylesheet` method
* Override of the Beasties `embedLinkedStylesheet` method
* that makes it work with Angular's CSP APIs.
*/
override async embedLinkedStylesheet(
@ -148,19 +147,19 @@ export class InlineCriticalCssProcessor extends CrittersBase {
const cspNonce = this.findCspNonce(document);
if (cspNonce) {
const crittersMedia = link.getAttribute('onload')?.match(MEDIA_SET_HANDLER_PATTERN);
const beastiesMedia = link.getAttribute('onload')?.match(MEDIA_SET_HANDLER_PATTERN);
if (crittersMedia) {
// If there's a Critters-generated `onload` handler and the file has an Angular CSP nonce,
if (beastiesMedia) {
// If there's a Beasties-generated `onload` handler and the file has an Angular CSP nonce,
// we have to remove the handler, because it's incompatible with CSP. We save the value
// in a different attribute and we generate a script tag with the nonce that uses
// `addEventListener` to apply the media query instead.
link.removeAttribute('onload');
link.setAttribute(CSP_MEDIA_ATTR, crittersMedia[1]);
link.setAttribute(CSP_MEDIA_ATTR, beastiesMedia[1]);
this.conditionallyInsertCspLoadingScript(document, cspNonce, link);
}
// Ideally we would hook in at the time Critters inserts the `style` tags, but there isn't
// Ideally we would hook in at the time Beasties inserts the `style` tags, but there isn't
// a way of doing that at the moment so we fall back to doing it any time a `link` tag is
// inserted. We mitigate it by only iterating the direct children of the `<head>` which
// should be pretty shallow.
@ -183,7 +182,7 @@ export class InlineCriticalCssProcessor extends CrittersBase {
return this.documentNonces.get(document)!;
}
// HTML attribute are case-insensitive, but the parser used by Critters is case-sensitive.
// HTML attribute are case-insensitive, but the parser used by Beasties is case-sensitive.
const nonceElement = document.querySelector('[ngCspNonce], [ngcspnonce]');
const cspNonce =
nonceElement?.getAttribute('ngCspNonce') || nonceElement?.getAttribute('ngcspnonce') || null;

View File

@ -21,7 +21,7 @@ jasmine_node_test(
)
genrule(
name = "critters_license_file",
name = "beasties_license_file",
srcs = [
"//packages/angular/ssr:npm_package",
],
@ -29,30 +29,30 @@ genrule(
"THIRD_PARTY_LICENSES.txt",
],
cmd = """
cp $(location //packages/angular/ssr:npm_package)/third_party/critters/THIRD_PARTY_LICENSES.txt $(location :THIRD_PARTY_LICENSES.txt)
cp $(location //packages/angular/ssr:npm_package)/third_party/beasties/THIRD_PARTY_LICENSES.txt $(location :THIRD_PARTY_LICENSES.txt)
""",
)
diff_test(
name = "critters_license_test",
name = "beasties_license_test",
failure_message = """
To accept the new golden file, execute:
yarn bazel run //packages/angular/ssr/test/npm_package:critters_license_test.accept
yarn bazel run //packages/angular/ssr/test/npm_package:beasties_license_test.accept
""",
file1 = ":THIRD_PARTY_LICENSES.txt.golden",
file2 = ":critters_license_file",
file2 = ":beasties_license_file",
)
write_file(
name = "critters_license_test.accept",
out = "critters_license_file_accept.sh",
name = "beasties_license_test.accept",
out = "beasties_license_file_accept.sh",
content =
[
"#!/usr/bin/env bash",
"cd ${BUILD_WORKSPACE_DIRECTORY}",
"yarn bazel build //packages/angular/ssr:npm_package",
"cp -fv dist/bin/packages/angular/ssr/npm_package/third_party/critters/THIRD_PARTY_LICENSES.txt packages/angular/ssr/test/npm_package/THIRD_PARTY_LICENSES.txt.golden",
"cp -fv dist/bin/packages/angular/ssr/npm_package/third_party/beasties/THIRD_PARTY_LICENSES.txt packages/angular/ssr/test/npm_package/THIRD_PARTY_LICENSES.txt.golden",
],
is_executable = True,
)

View File

@ -1,60 +1,215 @@
--------------------------------------------------------------------------------
Package: ansi-styles
License: "MIT"
Package: beasties
License: "Apache-2.0"
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2018 Google Inc.
Copyright 2024 Daniel Roe
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--------------------------------------------------------------------------------
Package: boolbase
License: "ISC"
--------------------------------------------------------------------------------
Package: chalk
License: "MIT"
--------------------------------------------------------------------------------
Package: color-convert
License: "MIT"
Copyright (c) 2011-2016 Heather Arthur <fayearthur@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
Package: color-name
License: "MIT"
The MIT License (MIT)
Copyright (c) 2015 Dmitry Ivanov
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
Package: critters
License: "Apache-2.0"
--------------------------------------------------------------------------------
Package: css-select
License: "BSD-2-Clause"
@ -317,11 +472,6 @@ Package: postcss-media-query-parser
License: "MIT"
--------------------------------------------------------------------------------
Package: supports-color
License: "MIT"
--------------------------------------------------------------------------------
Package: unenv
License: "MIT"

View File

@ -12,35 +12,35 @@ import { readFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';
/**
* Resolve paths for the Critters license file and the golden reference file.
* Resolve paths for the Beasties license file and the golden reference file.
*/
const ANGULAR_SSR_PACKAGE_PATH = dirname(
runfiles.resolve('angular_cli/packages/angular/ssr/npm_package/package.json'),
);
/**
* Path to the actual license file for the Critters library.
* This file is located in the `third_party/critters` directory of the Angular CLI npm package.
* Path to the actual license file for the Beasties library.
* This file is located in the `third_party/beasties` directory of the Angular CLI npm package.
*/
const CRITTERS_ACTUAL_LICENSE_FILE_PATH = join(
ANGULAR_SSR_PACKAGE_PATH,
'third_party/critters/THIRD_PARTY_LICENSES.txt',
'third_party/beasties/THIRD_PARTY_LICENSES.txt',
);
/**
* Path to the golden reference license file for the Critters library.
* Path to the golden reference license file for the Beasties library.
* This file is used as a reference for comparison and is located in the same directory as this script.
*/
const CRITTERS_GOLDEN_LICENSE_FILE_PATH = join(__dirname, 'THIRD_PARTY_LICENSES.txt.golden');
describe('NPM Package Tests', () => {
it('should not include the contents of third_party/critters/index.js in the FESM bundle', async () => {
it('should not include the contents of third_party/beasties/index.js in the FESM bundle', async () => {
const fesmFilePath = join(ANGULAR_SSR_PACKAGE_PATH, 'fesm2022/ssr.mjs');
const fesmContent = await readFile(fesmFilePath, 'utf-8');
expect(fesmContent).toContain(`import Critters from '../third_party/critters/index.js'`);
expect(fesmContent).toContain(`import Beasties from '../third_party/beasties/index.js'`);
});
describe('third_party/critters/THIRD_PARTY_LICENSES.txt', () => {
describe('third_party/beasties/THIRD_PARTY_LICENSES.txt', () => {
it('should exist', () => {
expect(existsSync(CRITTERS_ACTUAL_LICENSE_FILE_PATH)).toBe(true);
});

View File

@ -4,13 +4,13 @@ load("//tools:defaults.bzl", "js_library")
package(default_visibility = ["//visibility:public"])
esbuild(
name = "bundled_critters",
name = "bundled_beasties",
config = ":esbuild_config",
entry_point = "@npm//:node_modules/critters/dist/critters.mjs",
entry_point = "@npm//:node_modules/beasties/dist/index.mjs",
metafile = True,
splitting = True,
deps = [
"@npm//critters",
"@npm//beasties",
"@npm//unenv",
],
)
@ -21,21 +21,21 @@ esbuild_config(
)
js_library(
name = "bundled_critters_lib",
name = "bundled_beasties_lib",
srcs = [
"index.d.ts",
":bundled_critters_files",
":bundled_beasties_files",
],
deps = [
"@npm//critters",
"@npm//beasties",
],
)
# Filter out esbuild metadata files and only copy the necessary files
genrule(
name = "bundled_critters_files",
name = "bundled_beasties_files",
srcs = [
":bundled_critters",
":bundled_beasties",
],
outs = [
"index.js",
@ -43,9 +43,9 @@ genrule(
"THIRD_PARTY_LICENSES.txt",
],
cmd = """
for f in $(locations :bundled_critters); do
# Only process files inside the bundled_critters directory
if [[ "$${f}" == *bundled_critters ]]; then
for f in $(locations :bundled_beasties); do
# Only process files inside the bundled_beasties directory
if [[ "$${f}" == *bundled_beasties ]]; then
cp "$${f}/index.js" $(location :index.js)
cp "$${f}/index.js.map" $(location :index.js.map)
cp "$${f}/THIRD_PARTY_LICENSES.txt" $(location :THIRD_PARTY_LICENSES.txt)

View File

@ -18,8 +18,8 @@ export default {
entryNames: 'index',
legalComments: 'eof',
alias: {
fs,
path,
'node:fs': fs,
'node:path': path,
},
plugins: [
{

View File

@ -6,4 +6,4 @@
* found in the LICENSE file at https://angular.io/license
*/
export { default } from 'critters';
export { default } from 'beasties';

View File

@ -212,7 +212,7 @@ describe('Prerender Builder', () => {
/<style>p{color:#000}<\/style><link rel="stylesheet" href="styles\.\w+\.css" media="print" onload="this\.media='all'">/,
);
// Validate that critters does not process already critical css inlined stylesheets.
// Validate that beasties does not process already critical css inlined stylesheets.
expect(content).not.toContain(`onload="this.media='print'">`);
expect(content).not.toContain(`media="print"></noscript>`);
});

View File

@ -25,7 +25,7 @@ NPM_PACKAGE_SUBSTITUTIONS = {
"0.0.0-ENGINES-NPM": RELEASE_ENGINES_NPM,
"0.0.0-ENGINES-YARN": RELEASE_ENGINES_YARN,
# The below is needed for @angular/ssr FESM file.
"\\./(.+)/packages/angular/ssr/third_party/critters": "../third_party/critters/index.js",
"\\./(.+)/packages/angular/ssr/third_party/beasties": "../third_party/beasties/index.js",
}
NO_STAMP_PACKAGE_SUBSTITUTIONS = dict(NPM_PACKAGE_SUBSTITUTIONS, **{

View File

@ -382,8 +382,8 @@ __metadata:
"@babel/plugin-syntax-import-attributes": "npm:7.25.9"
"@inquirer/confirm": "npm:5.0.0"
"@vitejs/plugin-basic-ssl": "npm:1.1.0"
beasties: "npm:0.1.0"
browserslist: "npm:^4.23.0"
critters: "npm:0.0.25"
esbuild: "npm:0.24.0"
fast-glob: "npm:3.3.2"
https-proxy-agent: "npm:7.0.5"
@ -702,12 +702,12 @@ __metadata:
ansi-colors: "npm:4.1.3"
autoprefixer: "npm:10.4.20"
babel-loader: "npm:9.2.1"
beasties: "npm:0.1.0"
browser-sync: "npm:3.0.3"
browserslist: "npm:^4.21.5"
buffer: "npm:6.0.3"
chokidar: "npm:4.0.1"
copy-webpack-plugin: "npm:12.0.2"
critters: "npm:0.0.25"
css-loader: "npm:7.1.2"
debug: "npm:^4.1.1"
esbuild: "npm:0.24.0"
@ -7243,6 +7243,22 @@ __metadata:
languageName: node
linkType: hard
"beasties@npm:0.1.0":
version: 0.1.0
resolution: "beasties@npm:0.1.0"
dependencies:
css-select: "npm:^5.1.0"
css-what: "npm:^6.1.0"
dom-serializer: "npm:^2.0.0"
domhandler: "npm:^5.0.3"
htmlparser2: "npm:^9.0.0"
picocolors: "npm:^1.1.1"
postcss: "npm:^8.4.47"
postcss-media-query-parser: "npm:^0.2.3"
checksum: 10c0/62c7b6ad21283843e4de18d6458850a9b60bf3bedcb393b4a953144ace9617aa1fdc4f5eb3901c87aa428ebe24aaabe21af727b4e5c57965012b56bfbc0ed46a
languageName: node
linkType: hard
"before-after-hook@npm:^3.0.2":
version: 3.0.2
resolution: "before-after-hook@npm:3.0.2"
@ -8346,21 +8362,6 @@ __metadata:
languageName: node
linkType: hard
"critters@npm:0.0.25":
version: 0.0.25
resolution: "critters@npm:0.0.25"
dependencies:
chalk: "npm:^4.1.0"
css-select: "npm:^5.1.0"
dom-serializer: "npm:^2.0.0"
domhandler: "npm:^5.0.2"
htmlparser2: "npm:^8.0.2"
postcss: "npm:^8.4.23"
postcss-media-query-parser: "npm:^0.2.3"
checksum: 10c0/0129ca7f46fd49d69b85b3808c86d69267bda0dce9186b2a49f5e42fabd0e0d9e6153f707e9a8880712ce6bf3e257a696810157706bffafd92f6776fc777729b
languageName: node
linkType: hard
"cross-fetch@npm:3.1.5":
version: 3.1.5
resolution: "cross-fetch@npm:3.1.5"
@ -8899,7 +8900,7 @@ __metadata:
languageName: node
linkType: hard
"domutils@npm:^3.0.1":
"domutils@npm:^3.0.1, domutils@npm:^3.1.0":
version: 3.1.0
resolution: "domutils@npm:3.1.0"
dependencies:
@ -10859,6 +10860,18 @@ __metadata:
languageName: node
linkType: hard
"htmlparser2@npm:^9.0.0":
version: 9.1.0
resolution: "htmlparser2@npm:9.1.0"
dependencies:
domelementtype: "npm:^2.3.0"
domhandler: "npm:^5.0.3"
domutils: "npm:^3.1.0"
entities: "npm:^4.5.0"
checksum: 10c0/394f6323efc265bbc791d8c0d96bfe95984e0407565248521ab92e2dc7668e5ceeca7bc6ed18d408b9ee3b25032c5743368a4280d280332d782821d5d467ad8f
languageName: node
linkType: hard
"http-assert@npm:^1.3.0":
version: 1.5.0
resolution: "http-assert@npm:1.5.0"
@ -14657,7 +14670,7 @@ __metadata:
languageName: node
linkType: hard
"picocolors@npm:^1.0.0, picocolors@npm:^1.0.1, picocolors@npm:^1.1.0":
"picocolors@npm:^1.0.0, picocolors@npm:^1.0.1, picocolors@npm:^1.1.0, picocolors@npm:^1.1.1":
version: 1.1.1
resolution: "picocolors@npm:1.1.1"
checksum: 10c0/e2e3e8170ab9d7c7421969adaa7e1b31434f789afb9b3f115f6b96d91945041ac3ceb02e9ec6fe6510ff036bcc0bf91e69a1772edc0b707e12b19c0f2d6bcf58