Primeiro commit do projeto Angular
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
import { Rule } from '@angular-devkit/schematics';
|
||||
import { Schema as VitestBrowserOptions } from './schema';
|
||||
export default function (options: VitestBrowserOptions): Rule;
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
"use strict";
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
const schematics_1 = require("@angular-devkit/schematics");
|
||||
const posix_1 = require("node:path/posix");
|
||||
const dependency_1 = require("../utility/dependency");
|
||||
const json_file_1 = require("../utility/json-file");
|
||||
const latest_versions_1 = require("../utility/latest-versions");
|
||||
const workspace_1 = require("../utility/workspace");
|
||||
const workspace_models_1 = require("../utility/workspace-models");
|
||||
function default_1(options) {
|
||||
return async (host, _context) => {
|
||||
const workspace = await (0, workspace_1.getWorkspace)(host);
|
||||
const project = workspace.projects.get(options.project);
|
||||
if (!project) {
|
||||
throw new schematics_1.SchematicsException(`Project "${options.project}" does not exist.`);
|
||||
}
|
||||
const testTarget = project.targets.get('test');
|
||||
if (testTarget?.builder !== workspace_models_1.Builders.BuildUnitTest) {
|
||||
throw new schematics_1.SchematicsException(`Project "${options.project}" does not have a "test" target with a supported builder.`);
|
||||
}
|
||||
if (testTarget.options?.['runner'] === 'karma') {
|
||||
throw new schematics_1.SchematicsException(`Project "${options.project}" is configured to use Karma. ` +
|
||||
'Please migrate to Vitest before adding browser testing support.');
|
||||
}
|
||||
const packageName = options.package;
|
||||
if (!packageName) {
|
||||
return;
|
||||
}
|
||||
const dependencies = [packageName];
|
||||
if (packageName === '@vitest/browser-playwright') {
|
||||
dependencies.push('playwright');
|
||||
}
|
||||
else if (packageName === '@vitest/browser-webdriverio') {
|
||||
dependencies.push('webdriverio');
|
||||
}
|
||||
// Update tsconfig.spec.json
|
||||
const tsConfigPath = testTarget.options?.['tsConfig'] ??
|
||||
(0, posix_1.join)(project.root, 'tsconfig.spec.json');
|
||||
const updateTsConfigRule = (host) => {
|
||||
if (host.exists(tsConfigPath)) {
|
||||
const json = new json_file_1.JSONFile(host, tsConfigPath);
|
||||
const typesPath = ['compilerOptions', 'types'];
|
||||
const existingTypes = json.get(typesPath) ?? [];
|
||||
const newTypes = existingTypes.filter((t) => t !== 'jasmine');
|
||||
if (!newTypes.includes('vitest/globals')) {
|
||||
newTypes.push('vitest/globals');
|
||||
}
|
||||
if (packageName && !newTypes.includes(packageName)) {
|
||||
newTypes.push(packageName);
|
||||
}
|
||||
if (newTypes.length !== existingTypes.length ||
|
||||
newTypes.some((t, i) => t !== existingTypes[i])) {
|
||||
json.modify(typesPath, newTypes);
|
||||
}
|
||||
}
|
||||
};
|
||||
return (0, schematics_1.chain)([
|
||||
updateTsConfigRule,
|
||||
...dependencies.map((name) => (0, dependency_1.addDependency)(name, latest_versions_1.latestVersions[name], {
|
||||
type: dependency_1.DependencyType.Dev,
|
||||
existing: dependency_1.ExistingBehavior.Skip,
|
||||
install: options.skipInstall ? dependency_1.InstallBehavior.None : dependency_1.InstallBehavior.Auto,
|
||||
})),
|
||||
(_, context) => {
|
||||
context.logger.info('Vitest browser testing support has been added. ' +
|
||||
"To run tests in a browser, add a 'browsers' field to the 'test' target in 'angular.json', " +
|
||||
"or use the '--browsers' command line option.");
|
||||
},
|
||||
]);
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAsBH,4BAiFC;AArGD,2DAMoC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AY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAC3B,IAAA,0BAAa,EAAC,IAAI,EAAE,gCAAc,CAAC,IAAI,CAAC,EAAE;gBACxC,IAAI,EAAE,2BAAc,CAAC,GAAG;gBACxB,QAAQ,EAAE,6BAAgB,CAAC,IAAI;gBAC/B,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,4BAAe,CAAC,IAAI,CAAC,CAAC,CAAC,4BAAe,CAAC,IAAI;aAC3E,CAAC,CACH;YACD,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE;gBACb,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,iDAAiD;oBAC/C,4FAA4F;oBAC5F,8CAA8C,CACjD,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
export type Schema = {
|
||||
/**
|
||||
* The package to be added.
|
||||
*/
|
||||
package: string;
|
||||
/**
|
||||
* The name of the project.
|
||||
*/
|
||||
project: string;
|
||||
/**
|
||||
* Skip the automatic installation of packages. You will need to manually install the
|
||||
* dependencies later.
|
||||
*/
|
||||
skipInstall?: boolean;
|
||||
[property: string]: any;
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
// THIS FILE IS AUTOMATICALLY GENERATED. TO UPDATE THIS FILE YOU NEED TO CHANGE THE
|
||||
// CORRESPONDING JSON SCHEMA FILE, THEN RUN devkit-admin build (or bazel build ...).
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=schema.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"schema.js","sourceRoot":"","sources":["schema.ts"],"names":[],"mappings":";AACA,mFAAmF;AACnF,oFAAoF"}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema",
|
||||
"title": "Vitest Browser Provider Schematic",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"project": {
|
||||
"type": "string",
|
||||
"description": "The name of the project.",
|
||||
"$default": {
|
||||
"$source": "projectName"
|
||||
}
|
||||
},
|
||||
"package": {
|
||||
"type": "string",
|
||||
"description": "The package to be added."
|
||||
},
|
||||
"skipInstall": {
|
||||
"description": "Skip the automatic installation of packages. You will need to manually install the dependencies later.",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"required": ["project", "package"]
|
||||
}
|
||||
Reference in New Issue
Block a user