Skip to content

Commit

Permalink
Allow generateMap at a formats[] level
Browse files Browse the repository at this point in the history
You can now decide to output source maps for each format/output. Now you can have source maps for dev outputs and none for production outputs
  • Loading branch information
glenn2223 committed Aug 8, 2023
1 parent c37e4e2 commit 49bb79a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
10 changes: 6 additions & 4 deletions docs/faqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ Here's some of the most important changes:
- When `true` we will find a `.browserslistrc` file or `browserslist` in your `package.json`. No more duplicating settings!
- `showOutputWindow` is now `showOutputWindowOn` and uses log values (`Debug`, `Error`, etc.). It's default log level is `Information` - at this level it will output the same information that the original extension does
- Some settings are new!
- `formats[].savePathReplacementPairs`: replace segments in the output path
- `formats[].linefeed`: control the line terminator used
- `formats[].indentType`: control whether indents are spaces or tabs
- `formats[].indentWidth`: control the width of the indentation
- `formats[]`:
- `savePathReplacementPairs`: replace segments in the output path
- `generateMap`: generate map files at a format level (overwriting the top-tier setting of the same name)
- `linefeed`: control the line terminator used
- `indentType`: control whether indents are spaces or tabs
- `indentWidth`: control the width of the indentation
- `watchOnLaunch`: state whether you want to watch files upon launch
- `compileOnWatch`: state if files should be compiled upon watching
- `forceBaseDirectory`: state the base directory of all you SASS files. Aids in reducing wasted resources while searching for files
Expand Down
6 changes: 5 additions & 1 deletion docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ An array of formats. Allows you save to multiple locations, with a customisable
| extensionName | `.css` OR `.min.css` | `.css` | The extension appended to the outputted file |
| savePath | `string?` | `null` | See [save path notes] |
| savePathReplacementPairs | `Record<string, string>?` | `null` | See [save path notes] |
| generateMap | `boolean?` | `null` | Choose to output maps at a format level instead |
| <sup>Ŧ</sup>_linefeed_ | `cr` OR `crlf` OR `lf` OR `lfcr` | `lf` | The linefeed terminator to use |
| <sup>Ŧ</sup>_indentType_ | `space` OR `tab` | `space` | The indentation to use for the `expanded` format |
| <sup>Ŧ</sup>_indentWidth_ | `number` | `2` | The indentation width used for the `expanded` format |
Expand Down Expand Up @@ -70,7 +71,10 @@ An array of formats. Allows you save to multiple locations, with a customisable
"savePathReplacementPairs": {
"/SCSS/": "/Style/",
"/_SASS/": "/Style/"
}
},

// Don't create a map file for this "production" output
"generateMap": false
// Segment replacement can work with relative `savePath`s
{
"format": "compressed",
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@
],
"default": null
},
"generateMap": {
"description": "Generate a map for this particular output. Note: `null` uses the top level setting (of the same name)",
"type": [
"boolean",
"null"
],
"default": null
},
"linefeed": {
"description": "Choose the linefeed terminator to use in the CSS output",
"type": "string",
Expand Down
27 changes: 16 additions & 11 deletions src/appModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ export class AppModel {
return {
options,
pathData: this.generateCssAndMapUri(sassPath, format, workspaceFolder),
generateMap: format.generateMap,
};
})
);
Expand All @@ -361,7 +362,8 @@ export class AppModel {
sassPath,
result.css,
result.map,
data.options
data.options,
data.generateMap
)
: false
);
Expand Down Expand Up @@ -401,14 +403,16 @@ export class AppModel {
sassPath: string,
targetCssUri: string,
mapFileUri: string,
options: LegacyFileOptions<"sync"> | Options<"sync">
options: LegacyFileOptions<"sync"> | Options<"sync">,
formatGenerateMap: boolean | undefined
) {
OutputWindow.Show(OutputLevel.Trace, "Starting compilation", [
"Starting compilation of file",
`Path: ${sassPath}`,
]);

const generateMap = Helper.getConfigSettings<boolean>("generateMap", folder),
const generateMap =
formatGenerateMap ?? Helper.getConfigSettings<boolean>("generateMap", folder),
compileResult = SassHelper.compileOne(sassPath, targetCssUri, mapFileUri, options),
promises: Promise<IFileResolver>[] = [];

Expand Down Expand Up @@ -450,7 +454,8 @@ export class AppModel {
css,
map,
targetCssUri,
autoprefixerTarget
autoprefixerTarget,
generateMap
);
css = autoprefixerResult.css;
map = autoprefixerResult.map;
Expand Down Expand Up @@ -666,16 +671,16 @@ export class AppModel {
css: string,
map: string | undefined,
savePath: string,
browsers: string | Array<string> | true
browsers: string | Array<string> | true,
generateMap: boolean
): Promise<{ css: string; map: string | null }> {
OutputWindow.Show(OutputLevel.Trace, "Preparing autoprefixer");

const generateMap = Helper.getConfigSettings<boolean>("generateMap", folder),
prefixer = postcss(
autoprefixer({
overrideBrowserslist: browsers === true ? undefined : browsers,
})
);
const prefixer = postcss(
autoprefixer({
overrideBrowserslist: browsers === true ? undefined : browsers,
})
);

// TODO: REMOVE - when autoprefixer can stop caching the browsers
const oldBrowserlistCache = process.env.BROWSERSLIST_DISABLE_CACHE;
Expand Down
7 changes: 3 additions & 4 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export interface IFormat {
format: "compressed" | "expanded";
extensionName: string;
savePath?: string;
savePathReplacementPairs?: Record<string, unknown>,
savePathReplacementPairs?: Record<string, unknown>;
generateMap?: boolean;
linefeed: "cr" | "crlf" | "lf" | "lfcr";
indentType: "space" | "tab";
indentWidth: number;
Expand Down Expand Up @@ -41,9 +42,7 @@ export class Helper {
default: {
const oldSetting = this.configSettings().get("showOutputWindow") as boolean | null;

return oldSetting == false
? OutputLevel.Warning
: OutputLevel.Information;
return oldSetting == false ? OutputLevel.Warning : OutputLevel.Information;
}
}
}
Expand Down

0 comments on commit 49bb79a

Please sign in to comment.