From a5f16cc3943ffd9eddf02662bedfb1df94ac845e Mon Sep 17 00:00:00 2001 From: Jonas Bengtsson Date: Mon, 19 Jul 2021 18:30:33 +0200 Subject: [PATCH] Extract default sass plugin from heft to its own heft-sass-plugin --- apps/heft/package.json | 4 -- .../heft/src/pluginFramework/PluginManager.ts | 2 - apps/heft/src/templates/sass.json | 47 ---------------- apps/heft/src/utilities/CoreConfigFiles.ts | 23 -------- apps/heft/tsconfig.json | 2 +- build-tests/heft-sass-test/config/heft.json | 6 +++ build-tests/heft-sass-test/package.json | 1 + .../rush/browser-approved-packages.json | 4 ++ common/config/rush/pnpm-lock.yaml | 45 +++++++++++++--- common/config/rush/repo-state.json | 2 +- common/reviews/api/heft-sass-plugin.api.md | 13 +++++ heft-plugins/heft-sass-plugin/.eslintrc.js | 10 ++++ heft-plugins/heft-sass-plugin/.npmignore | 30 +++++++++++ heft-plugins/heft-sass-plugin/LICENSE | 24 +++++++++ heft-plugins/heft-sass-plugin/README.md | 11 ++++ .../config/api-extractor.json | 16 ++++++ heft-plugins/heft-sass-plugin/config/rig.json | 7 +++ .../custom-typings/postcss-modules/index.d.ts | 0 heft-plugins/heft-sass-plugin/package.json | 39 ++++++++++++++ .../src}/SassTypingsGenerator.ts | 6 +-- .../src}/SassTypingsPlugin.ts | 53 ++++++++++++++----- heft-plugins/heft-sass-plugin/src/index.ts | 16 ++++++ .../src/schemas/heft-sass-plugin.schema.json | 0 heft-plugins/heft-sass-plugin/tsconfig.json | 8 +++ rush.json | 6 +++ 25 files changed, 273 insertions(+), 102 deletions(-) delete mode 100644 apps/heft/src/templates/sass.json create mode 100644 common/reviews/api/heft-sass-plugin.api.md create mode 100644 heft-plugins/heft-sass-plugin/.eslintrc.js create mode 100644 heft-plugins/heft-sass-plugin/.npmignore create mode 100644 heft-plugins/heft-sass-plugin/LICENSE create mode 100644 heft-plugins/heft-sass-plugin/README.md create mode 100644 heft-plugins/heft-sass-plugin/config/api-extractor.json create mode 100644 heft-plugins/heft-sass-plugin/config/rig.json rename {apps/heft => heft-plugins/heft-sass-plugin}/custom-typings/postcss-modules/index.d.ts (100%) create mode 100644 heft-plugins/heft-sass-plugin/package.json rename {apps/heft/src/plugins/SassTypingsPlugin => heft-plugins/heft-sass-plugin/src}/SassTypingsGenerator.ts (100%) rename {apps/heft/src/plugins/SassTypingsPlugin => heft-plugins/heft-sass-plugin/src}/SassTypingsPlugin.ts (56%) create mode 100644 heft-plugins/heft-sass-plugin/src/index.ts rename apps/heft/src/schemas/sass.schema.json => heft-plugins/heft-sass-plugin/src/schemas/heft-sass-plugin.schema.json (100%) create mode 100644 heft-plugins/heft-sass-plugin/tsconfig.json diff --git a/apps/heft/package.json b/apps/heft/package.json index eb2c1476b85..9ef1bbe6b85 100644 --- a/apps/heft/package.json +++ b/apps/heft/package.json @@ -42,9 +42,6 @@ "fast-glob": "~3.2.4", "glob": "~7.0.5", "glob-escape": "~0.0.2", - "node-sass": "5.0.0", - "postcss": "7.0.32", - "postcss-modules": "~1.5.0", "prettier": "~2.3.0", "semver": "~7.3.0", "tapable": "1.1.3", @@ -60,7 +57,6 @@ "@types/glob": "7.1.1", "@types/heft-jest": "1.0.1", "@types/node": "10.17.13", - "@types/node-sass": "4.11.1", "@types/semver": "7.3.5", "colors": "~1.2.1", "tslint": "~5.20.1", diff --git a/apps/heft/src/pluginFramework/PluginManager.ts b/apps/heft/src/pluginFramework/PluginManager.ts index 74243950397..3da2fa7ea6a 100644 --- a/apps/heft/src/pluginFramework/PluginManager.ts +++ b/apps/heft/src/pluginFramework/PluginManager.ts @@ -20,7 +20,6 @@ import { DeleteGlobsPlugin } from '../plugins/DeleteGlobsPlugin'; import { CopyStaticAssetsPlugin } from '../plugins/CopyStaticAssetsPlugin'; import { RunScriptPlugin } from '../plugins/RunScriptPlugin'; import { ApiExtractorPlugin } from '../plugins/ApiExtractorPlugin/ApiExtractorPlugin'; -import { SassTypingsPlugin } from '../plugins/SassTypingsPlugin/SassTypingsPlugin'; import { ProjectValidatorPlugin } from '../plugins/ProjectValidatorPlugin'; import { ToolPackageResolver } from '../utilities/ToolPackageResolver'; import { NodeServicePlugin } from '../plugins/NodeServicePlugin'; @@ -53,7 +52,6 @@ export class PluginManager { this._applyPlugin(new DeleteGlobsPlugin()); this._applyPlugin(new RunScriptPlugin()); this._applyPlugin(new ApiExtractorPlugin(taskPackageResolver)); - this._applyPlugin(new SassTypingsPlugin()); this._applyPlugin(new ProjectValidatorPlugin()); this._applyPlugin(new NodeServicePlugin()); } diff --git a/apps/heft/src/templates/sass.json b/apps/heft/src/templates/sass.json deleted file mode 100644 index f2bbfd9fc32..00000000000 --- a/apps/heft/src/templates/sass.json +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Configures the Sass Typings plugin for the Heft build system. - * - * This optional additional file customizes Sass parsing, module resolution, and emitting of - * typings files for the Typescript compiler. - */ -{ - "$schema": "https://developer.microsoft.com/json-schemas/heft/sass.schema.json" - - /** - * Source code root directory. - * This is where .css, .sass, and .scss files will be searched for to generate typings. - */ - // "srcFolder": "src", - - /** - * Output directory for generated Sass typings. - */ - // "generatedTsFolder": "temp/sass-ts", - - /** - * Determines if export values are wrapped in a default property, or not. - */ - // "exportAsDefault": true, - - /** - * Files with these extensions will pass through the Sass transpiler for typings generation. - */ - // "fileExtensions": [ - // ".sass", - // ".scss", - // ".css - // ], - - /** - * A list of paths used when resolving Sass imports. - */ - // "importIncludePaths": [ - // "node_modules", - // "src" - // ], - - /** - * A list of file paths relative to the "src" folder that should be excluded from typings generation. - */ - // "excludeFiles": [] -} diff --git a/apps/heft/src/utilities/CoreConfigFiles.ts b/apps/heft/src/utilities/CoreConfigFiles.ts index 7d4b66d594a..4850478866f 100644 --- a/apps/heft/src/utilities/CoreConfigFiles.ts +++ b/apps/heft/src/utilities/CoreConfigFiles.ts @@ -13,7 +13,6 @@ import { IApiExtractorPluginConfiguration } from '../plugins/ApiExtractorPlugin/ import { ITypeScriptConfigurationJson } from '../plugins/TypeScriptPlugin/TypeScriptPlugin'; import { HeftConfiguration } from '../configuration/HeftConfiguration'; import { Terminal } from '@rushstack/node-core-library'; -import { ISassConfigurationJson } from '../plugins/SassTypingsPlugin/SassTypingsPlugin'; import { INodeServicePluginConfiguration } from '../plugins/NodeServicePlugin'; export enum HeftEvent { @@ -125,7 +124,6 @@ export class CoreConfigFiles { private static _nodeServiceConfigurationLoader: | ConfigurationFile | undefined; - private static _sassConfigurationFileLoader: ConfigurationFile | undefined; /** * Returns the loader for the `config/heft.json` config file. @@ -283,27 +281,6 @@ export class CoreConfigFiles { return CoreConfigFiles._nodeServiceConfigurationLoader; } - public static get sassConfigurationFileLoader(): ConfigurationFile { - const schemaPath: string = path.resolve(__dirname, '..', 'schemas', 'sass.schema.json'); - CoreConfigFiles._sassConfigurationFileLoader = new ConfigurationFile({ - projectRelativeFilePath: 'config/sass.json', - jsonSchemaPath: schemaPath, - jsonPathMetadata: { - '$.importIncludePaths.*': { - pathResolutionMethod: PathResolutionMethod.resolvePathRelativeToProjectRoot - }, - '$.generatedTsFolder.*': { - pathResolutionMethod: PathResolutionMethod.resolvePathRelativeToProjectRoot - }, - '$.srcFolder.*': { - pathResolutionMethod: PathResolutionMethod.resolvePathRelativeToProjectRoot - } - } - }); - - return CoreConfigFiles._sassConfigurationFileLoader; - } - private static _addEventActionToMap( eventAction: TEventAction, map: Map diff --git a/apps/heft/tsconfig.json b/apps/heft/tsconfig.json index 5f8c39781a3..b7e85cd1768 100644 --- a/apps/heft/tsconfig.json +++ b/apps/heft/tsconfig.json @@ -5,5 +5,5 @@ "typeRoots": ["./custom-typings", "./node_modules/@types/"], "types": ["heft-jest", "node"] }, - "include": ["src/**/*.ts", "src/**/*.tsx", "./custom-typings/**/*.ts"] + "include": ["src/**/*.ts", "src/**/*.tsx"] } diff --git a/build-tests/heft-sass-test/config/heft.json b/build-tests/heft-sass-test/config/heft.json index 5ba3c430247..1e7f17a677d 100644 --- a/build-tests/heft-sass-test/config/heft.json +++ b/build-tests/heft-sass-test/config/heft.json @@ -52,6 +52,12 @@ * The path to the plugin package. */ "plugin": "@rushstack/heft-jest-plugin" + }, + { + /** + * The path to the plugin package. + */ + "plugin": "@rushstack/heft-sass-plugin" } ] } diff --git a/build-tests/heft-sass-test/package.json b/build-tests/heft-sass-test/package.json index 78c33518cde..afff23c68fe 100644 --- a/build-tests/heft-sass-test/package.json +++ b/build-tests/heft-sass-test/package.json @@ -11,6 +11,7 @@ "@rushstack/eslint-config": "workspace:*", "@rushstack/heft": "workspace:*", "@rushstack/heft-jest-plugin": "workspace:*", + "@rushstack/heft-sass-plugin": "workspace:*", "@rushstack/heft-webpack4-plugin": "workspace:*", "@types/heft-jest": "1.0.1", "@types/react-dom": "16.9.8", diff --git a/common/config/rush/browser-approved-packages.json b/common/config/rush/browser-approved-packages.json index 5e3f614e8b6..24be0af0202 100644 --- a/common/config/rush/browser-approved-packages.json +++ b/common/config/rush/browser-approved-packages.json @@ -2,6 +2,10 @@ { "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/approved-packages.schema.json", "packages": [ + { + "name": "@rushstack/heft-sass-plugin", + "allowedCategories": [ "tests" ] + }, { "name": "react", "allowedCategories": [ "tests" ] diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index b6745b09f94..ce56ca3834f 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -122,7 +122,6 @@ importers: '@types/glob': 7.1.1 '@types/heft-jest': 1.0.1 '@types/node': 10.17.13 - '@types/node-sass': 4.11.1 '@types/semver': 7.3.5 '@types/tapable': 1.0.6 argparse: ~1.0.9 @@ -131,9 +130,6 @@ importers: fast-glob: ~3.2.4 glob: ~7.0.5 glob-escape: ~0.0.2 - node-sass: 5.0.0 - postcss: 7.0.32 - postcss-modules: ~1.5.0 prettier: ~2.3.0 semver: ~7.3.0 tapable: 1.1.3 @@ -152,9 +148,6 @@ importers: fast-glob: 3.2.7 glob: 7.0.6 glob-escape: 0.0.2 - node-sass: 5.0.0 - postcss: 7.0.32 - postcss-modules: 1.5.0 prettier: 2.3.2 semver: 7.3.5 tapable: 1.1.3 @@ -169,7 +162,6 @@ importers: '@types/glob': 7.1.1 '@types/heft-jest': 1.0.1 '@types/node': 10.17.13 - '@types/node-sass': 4.11.1 '@types/semver': 7.3.5 colors: 1.2.5 tslint: 5.20.1_typescript@3.9.10 @@ -757,6 +749,7 @@ importers: '@rushstack/eslint-config': workspace:* '@rushstack/heft': workspace:* '@rushstack/heft-jest-plugin': workspace:* + '@rushstack/heft-sass-plugin': workspace:* '@rushstack/heft-webpack4-plugin': workspace:* '@types/heft-jest': 1.0.1 '@types/react': 16.9.45 @@ -782,6 +775,7 @@ importers: '@rushstack/eslint-config': link:../../stack/eslint-config '@rushstack/heft': link:../../apps/heft '@rushstack/heft-jest-plugin': link:../../heft-plugins/heft-jest-plugin + '@rushstack/heft-sass-plugin': link:../../heft-plugins/heft-sass-plugin '@rushstack/heft-webpack4-plugin': link:../../heft-plugins/heft-webpack4-plugin '@types/heft-jest': 1.0.1 '@types/react': 16.9.45 @@ -1033,6 +1027,41 @@ importers: jest-environment-node: 25.4.0 typescript: 3.9.10 + ../../heft-plugins/heft-sass-plugin: + specifiers: + '@microsoft/api-extractor': workspace:* + '@rushstack/eslint-config': workspace:* + '@rushstack/heft': workspace:* + '@rushstack/heft-config-file': workspace:* + '@rushstack/heft-node-rig': workspace:* + '@rushstack/node-core-library': workspace:* + '@rushstack/typings-generator': workspace:* + '@types/heft-jest': 1.0.1 + '@types/node': 10.17.13 + '@types/node-sass': 4.11.1 + eslint: ~7.30.0 + node-sass: 5.0.0 + postcss: 7.0.32 + postcss-modules: ~1.5.0 + typescript: ~3.9.7 + dependencies: + '@rushstack/heft-config-file': link:../../libraries/heft-config-file + '@rushstack/node-core-library': link:../../libraries/node-core-library + '@rushstack/typings-generator': link:../../libraries/typings-generator + node-sass: 5.0.0 + postcss: 7.0.32 + postcss-modules: 1.5.0 + devDependencies: + '@microsoft/api-extractor': link:../../apps/api-extractor + '@rushstack/eslint-config': link:../../stack/eslint-config + '@rushstack/heft': link:../../apps/heft + '@rushstack/heft-node-rig': link:../../rigs/heft-node-rig + '@types/heft-jest': 1.0.1 + '@types/node': 10.17.13 + '@types/node-sass': 4.11.1 + eslint: 7.30.0 + typescript: 3.9.10 + ../../heft-plugins/heft-webpack4-plugin: specifiers: '@rushstack/eslint-config': workspace:* diff --git a/common/config/rush/repo-state.json b/common/config/rush/repo-state.json index 303ff3c4193..1d371162ce7 100644 --- a/common/config/rush/repo-state.json +++ b/common/config/rush/repo-state.json @@ -1,5 +1,5 @@ // DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush. { - "pnpmShrinkwrapHash": "f45464cdd2ef1f79ab3446b3edd2384175b1e967", + "pnpmShrinkwrapHash": "90d9a6f48b14750485b141fc7547965bcb69bb9f", "preferredVersionsHash": "1fbc26d2c5b3248616b9edccd6bef064075243bc" } diff --git a/common/reviews/api/heft-sass-plugin.api.md b/common/reviews/api/heft-sass-plugin.api.md new file mode 100644 index 00000000000..b00a09a3568 --- /dev/null +++ b/common/reviews/api/heft-sass-plugin.api.md @@ -0,0 +1,13 @@ +## API Report File for "@rushstack/heft-sass-plugin" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +import type { IHeftPlugin } from '@rushstack/heft'; + +// @public (undocumented) +const _default: IHeftPlugin; +export default _default; + +``` diff --git a/heft-plugins/heft-sass-plugin/.eslintrc.js b/heft-plugins/heft-sass-plugin/.eslintrc.js new file mode 100644 index 00000000000..4c934799d67 --- /dev/null +++ b/heft-plugins/heft-sass-plugin/.eslintrc.js @@ -0,0 +1,10 @@ +// This is a workaround for https://github.com/eslint/eslint/issues/3458 +require('@rushstack/eslint-config/patch/modern-module-resolution'); + +module.exports = { + extends: [ + '@rushstack/eslint-config/profile/node-trusted-tool', + '@rushstack/eslint-config/mixins/friendly-locals' + ], + parserOptions: { tsconfigRootDir: __dirname } +}; diff --git a/heft-plugins/heft-sass-plugin/.npmignore b/heft-plugins/heft-sass-plugin/.npmignore new file mode 100644 index 00000000000..0164a20d7a9 --- /dev/null +++ b/heft-plugins/heft-sass-plugin/.npmignore @@ -0,0 +1,30 @@ +# THIS IS A STANDARD TEMPLATE FOR .npmignore FILES IN THIS REPO. + +# Ignore all files by default, to avoid accidentally publishing unintended files. +* + +# Use negative patterns to bring back the specific things we want to publish. +!/bin/** +!/lib/** +!/lib-*/** +!/dist/** +!ThirdPartyNotice.txt + +# Ignore certain patterns that should not get published. +/dist/*.stats.* +/lib/**/test/ +/lib-*/**/test/ +*.test.js + +# NOTE: These don't need to be specified, because NPM includes them automatically. +# +# package.json +# README (and its variants) +# CHANGELOG (and its variants) +# LICENSE / LICENCE + +#-------------------------------------------- +# DO NOT MODIFY THE TEMPLATE ABOVE THIS LINE +#-------------------------------------------- + +# (Add your project-specific overrides here) diff --git a/heft-plugins/heft-sass-plugin/LICENSE b/heft-plugins/heft-sass-plugin/LICENSE new file mode 100644 index 00000000000..40e2a06dc72 --- /dev/null +++ b/heft-plugins/heft-sass-plugin/LICENSE @@ -0,0 +1,24 @@ +@rushstack/heft-sass-plugin + +Copyright (c) Microsoft Corporation. All rights reserved. + +MIT License + +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. diff --git a/heft-plugins/heft-sass-plugin/README.md b/heft-plugins/heft-sass-plugin/README.md new file mode 100644 index 00000000000..d8bc571794b --- /dev/null +++ b/heft-plugins/heft-sass-plugin/README.md @@ -0,0 +1,11 @@ +# @rushstack/heft-sass-plugin + +This is a Heft plugin for using node-sass during the "build" stage. + +## Links + +- [CHANGELOG.md]( + https://github.com/microsoft/rushstack/blob/master/heft-plugins/heft-sass-plugin/CHANGELOG.md) - Find + out what's new in the latest version + +Heft is part of the [Rush Stack](https://rushstack.io/) family of projects. diff --git a/heft-plugins/heft-sass-plugin/config/api-extractor.json b/heft-plugins/heft-sass-plugin/config/api-extractor.json new file mode 100644 index 00000000000..74590d3c4f8 --- /dev/null +++ b/heft-plugins/heft-sass-plugin/config/api-extractor.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", + + "mainEntryPointFilePath": "/lib/index.d.ts", + "apiReport": { + "enabled": true, + "reportFolder": "../../../common/reviews/api" + }, + "docModel": { + "enabled": false + }, + "dtsRollup": { + "enabled": true, + "betaTrimmedFilePath": "/dist/.d.ts" + } +} diff --git a/heft-plugins/heft-sass-plugin/config/rig.json b/heft-plugins/heft-sass-plugin/config/rig.json new file mode 100644 index 00000000000..6ac88a96368 --- /dev/null +++ b/heft-plugins/heft-sass-plugin/config/rig.json @@ -0,0 +1,7 @@ +{ + // The "rig.json" file directs tools to look for their config files in an external package. + // Documentation for this system: https://www.npmjs.com/package/@rushstack/rig-package + "$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json", + + "rigPackageName": "@rushstack/heft-node-rig" +} diff --git a/apps/heft/custom-typings/postcss-modules/index.d.ts b/heft-plugins/heft-sass-plugin/custom-typings/postcss-modules/index.d.ts similarity index 100% rename from apps/heft/custom-typings/postcss-modules/index.d.ts rename to heft-plugins/heft-sass-plugin/custom-typings/postcss-modules/index.d.ts diff --git a/heft-plugins/heft-sass-plugin/package.json b/heft-plugins/heft-sass-plugin/package.json new file mode 100644 index 00000000000..fbae5d4cb06 --- /dev/null +++ b/heft-plugins/heft-sass-plugin/package.json @@ -0,0 +1,39 @@ +{ + "name": "@rushstack/heft-sass-plugin", + "version": "0.1.0", + "description": "Heft plugin for SASS", + "repository": { + "type": "git", + "url": "https://github.com/microsoft/rushstack/tree/master/heft-plugins/heft-sass-plugin" + }, + "homepage": "https://rushstack.io/pages/heft/overview/", + "main": "lib/index.js", + "types": "dist/heft-sass-plugin.d.ts", + "license": "MIT", + "scripts": { + "build": "heft test --clean", + "start": "heft test --clean --watch" + }, + "peerDependencies": { + "@rushstack/heft": "^0.34.8" + }, + "dependencies": { + "@rushstack/heft-config-file": "workspace:*", + "@rushstack/node-core-library": "workspace:*", + "@rushstack/typings-generator": "workspace:*", + "node-sass": "5.0.0", + "postcss": "7.0.32", + "postcss-modules": "~1.5.0" + }, + "devDependencies": { + "@microsoft/api-extractor": "workspace:*", + "@rushstack/eslint-config": "workspace:*", + "@rushstack/heft": "workspace:*", + "@rushstack/heft-node-rig": "workspace:*", + "@types/heft-jest": "1.0.1", + "@types/node": "10.17.13", + "@types/node-sass": "4.11.1", + "eslint": "~7.30.0", + "typescript": "~3.9.7" + } +} diff --git a/apps/heft/src/plugins/SassTypingsPlugin/SassTypingsGenerator.ts b/heft-plugins/heft-sass-plugin/src/SassTypingsGenerator.ts similarity index 100% rename from apps/heft/src/plugins/SassTypingsPlugin/SassTypingsGenerator.ts rename to heft-plugins/heft-sass-plugin/src/SassTypingsGenerator.ts index 8ba7510cd8c..723ee004760 100644 --- a/apps/heft/src/plugins/SassTypingsPlugin/SassTypingsGenerator.ts +++ b/heft-plugins/heft-sass-plugin/src/SassTypingsGenerator.ts @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import * as path from 'path'; +import { LegacyAdapters } from '@rushstack/node-core-library'; +import { IStringValueTypings, StringValuesTypingsGenerator } from '@rushstack/typings-generator'; import { render, Result } from 'node-sass'; +import * as path from 'path'; import postcss from 'postcss'; import cssModules from 'postcss-modules'; -import { LegacyAdapters } from '@rushstack/node-core-library'; -import { IStringValueTypings, StringValuesTypingsGenerator } from '@rushstack/typings-generator'; /** * @public diff --git a/apps/heft/src/plugins/SassTypingsPlugin/SassTypingsPlugin.ts b/heft-plugins/heft-sass-plugin/src/SassTypingsPlugin.ts similarity index 56% rename from apps/heft/src/plugins/SassTypingsPlugin/SassTypingsPlugin.ts rename to heft-plugins/heft-sass-plugin/src/SassTypingsPlugin.ts index 951cdc3cb73..f39f4c2e59b 100644 --- a/apps/heft/src/plugins/SassTypingsPlugin/SassTypingsPlugin.ts +++ b/heft-plugins/heft-sass-plugin/src/SassTypingsPlugin.ts @@ -1,21 +1,28 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import { IHeftPlugin } from '../../pluginFramework/IHeftPlugin'; -import { HeftSession } from '../../pluginFramework/HeftSession'; -import { HeftConfiguration } from '../../configuration/HeftConfiguration'; -import { IBuildStageContext, IPreCompileSubstage } from '../../stages/BuildStage'; +import { + HeftConfiguration, + HeftSession, + IBuildStageContext, + IHeftPlugin, + IPreCompileSubstage, + ScopedLogger +} from '@rushstack/heft'; +import { ConfigurationFile, PathResolutionMethod } from '@rushstack/heft-config-file'; +import { JsonSchema } from '@rushstack/node-core-library'; +import * as path from 'path'; import { ISassConfiguration, SassTypingsGenerator } from './SassTypingsGenerator'; -import { CoreConfigFiles } from '../../utilities/CoreConfigFiles'; -import { ScopedLogger } from '../../pluginFramework/logging/ScopedLogger'; -import { Async } from '../../utilities/Async'; export interface ISassConfigurationJson extends ISassConfiguration {} const PLUGIN_NAME: string = 'SassTypingsPlugin'; +const PLUGIN_SCHEMA_PATH: string = path.resolve(__dirname, 'schemas', 'heft-sass-plugin.schema.json'); +const SASS_CONFIGURATION_LOCATION: string = `config/sass.json`; export class SassTypingsPlugin implements IHeftPlugin { public readonly pluginName: string = PLUGIN_NAME; + public readonly optionsSchema: JsonSchema = JsonSchema.fromFile(PLUGIN_SCHEMA_PATH); /** * Generate typings for Sass files before TypeScript compilation. @@ -51,7 +58,11 @@ export class SassTypingsPlugin implements IHeftPlugin { await sassTypingsGenerator.generateTypingsAsync(); if (isWatchMode) { - Async.runWatcherWithErrorHandling(async () => await sassTypingsGenerator.runWatcherAsync(), logger); + try { + await sassTypingsGenerator.runWatcherAsync(); + } catch (e) { + logger.emitError(e); + } } } @@ -61,14 +72,30 @@ export class SassTypingsPlugin implements IHeftPlugin { ): Promise { const { buildFolder } = heftConfiguration; const sassConfigurationJson: ISassConfigurationJson | undefined = - await CoreConfigFiles.sassConfigurationFileLoader.tryLoadConfigurationFileForProjectAsync( - logger.terminal, - buildFolder, - heftConfiguration.rigConfig - ); + await SassTypingsPlugin._getSassConfigurationLoader( + buildFolder + ).tryLoadConfigurationFileForProjectAsync(logger.terminal, buildFolder, heftConfiguration.rigConfig); return { ...sassConfigurationJson }; } + + private static _getSassConfigurationLoader(buildFolder: string): ConfigurationFile { + return new ConfigurationFile({ + projectRelativeFilePath: SASS_CONFIGURATION_LOCATION, + jsonSchemaPath: PLUGIN_SCHEMA_PATH, + jsonPathMetadata: { + '$.importIncludePaths.*': { + pathResolutionMethod: PathResolutionMethod.resolvePathRelativeToProjectRoot + }, + '$.generatedTsFolder.*': { + pathResolutionMethod: PathResolutionMethod.resolvePathRelativeToProjectRoot + }, + '$.srcFolder.*': { + pathResolutionMethod: PathResolutionMethod.resolvePathRelativeToProjectRoot + } + } + }); + } } diff --git a/heft-plugins/heft-sass-plugin/src/index.ts b/heft-plugins/heft-sass-plugin/src/index.ts new file mode 100644 index 00000000000..a454598eabf --- /dev/null +++ b/heft-plugins/heft-sass-plugin/src/index.ts @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +/** + * A Heft plugin for using node-sass during the "build" stage. + * + * @packageDocumentation + */ + +import type { IHeftPlugin } from '@rushstack/heft'; +import { SassTypingsPlugin } from './SassTypingsPlugin'; + +/** + * @internal + */ +export default new SassTypingsPlugin() as IHeftPlugin; diff --git a/apps/heft/src/schemas/sass.schema.json b/heft-plugins/heft-sass-plugin/src/schemas/heft-sass-plugin.schema.json similarity index 100% rename from apps/heft/src/schemas/sass.schema.json rename to heft-plugins/heft-sass-plugin/src/schemas/heft-sass-plugin.schema.json diff --git a/heft-plugins/heft-sass-plugin/tsconfig.json b/heft-plugins/heft-sass-plugin/tsconfig.json new file mode 100644 index 00000000000..ff8c38a3615 --- /dev/null +++ b/heft-plugins/heft-sass-plugin/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "./node_modules/@rushstack/heft-node-rig/profiles/default/tsconfig-base.json", + + "compilerOptions": { + "types": ["node"] + }, + "include": ["src/**/*.ts", "./custom-typings/**/*.ts"] +} diff --git a/rush.json b/rush.json index 1fc7c74ce02..52fa9c0bcdf 100644 --- a/rush.json +++ b/rush.json @@ -693,6 +693,12 @@ "reviewCategory": "libraries", "shouldPublish": true }, + { + "packageName": "@rushstack/heft-sass-plugin", + "projectFolder": "heft-plugins/heft-sass-plugin", + "reviewCategory": "libraries", + "shouldPublish": true + }, { "packageName": "@rushstack/heft-webpack4-plugin", "projectFolder": "heft-plugins/heft-webpack4-plugin",