Skip to content

Commit

Permalink
Merge pull request #111 from elycruz/dev
Browse files Browse the repository at this point in the history
maintenance: (node fs module) deprecation warnings removal and annotations
  • Loading branch information
elycruz authored Feb 26, 2023
2 parents 2370810 + 403b88b commit c6e45f1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup-plugin-sass",
"version": "1.12.17",
"version": "1.12.18",
"description": "Rollup Sass files.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
6 changes: 5 additions & 1 deletion scripts/clean-and-run-downlevel-dts.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ const fs = require('fs').promises,

// Run 'clean-and-run' process
(async () =>
fs.rmdir(outputDir, {recursive: true})

// @note Conditional check here since we have a relaxed 'package.json.engines.node' value,
// and `fs.rmdir` is being deprecated in later versions of node (node v18+).
// ----
(fs.rm ? fs.rm : fs.rmdir)(outputDir, {recursive: true})

.then(() => fs.mkdir(outputDir))

Expand Down
16 changes: 10 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ const MATCH_SASS_FILENAME_RE = /\.sass$/,
let lastResult = Promise.resolve();

/**
* Legacy Sass (*.scss/*.sass) file importer (works in new, and older, versions of `sass` module).
* Legacy Sass (*.scss/*.sass) file importer (works in new (< v2.0), and older, versions of `sass` (dart-sass) module).
*
* @see https://sass-lang.com/documentation/js-api/modules#LegacyAsyncImporter
* @param {string} url - Url found in `@import`/`@use`, found in parent sass file, exactly as it appears in sass file.
* @param {string} prevUrl - Url of file that contains '@import' rule for `url`.
* @param {(result: LegacyImporterResult | SassImporterResult) => void} done - Signals import completion. Note: `LegacyImporterResult`, and `SassImporterResult`, are the same here - We've defined the type for out plugin, since older versions of sass don't have the type defined amongst their types.
*
* @param {string} url - Url found in `@import`/`@use`, found in parent sass file; E.g., exactly as it appears in sass file.
* @param {string} prevUrl - Url of file that contains '@import' rule for incoming file (`url`).
* @param {(result: LegacyImporterResult | SassImporterResult) => void} done - Signals import completion. Note: `LegacyImporterResult`, and `SassImporterResult`, are the same here - We've defined the type for our plugin, since older versions of sass don't have this type defined.
* @note This importer may not work in dart-sass v2.0+ (which may be far off in the future, but is important to note: https://sass-lang.com/documentation/js-api/#legacy-api).
* @returns {void}
*/
const importer1 = (url: string, prevUrl: string, done: (rslt: SassImporterResult) => void): void => {
Expand Down Expand Up @@ -68,8 +71,9 @@ const MATCH_SASS_FILENAME_RE = /\.sass$/,
file: url,
}));
}
}
return [importer1].concat(sassOptions.importer || [])
};

return [importer1].concat(sassOptions.importer || []);
},

processRenderResponse = (rollupOptions, file, state, inCss) => {
Expand Down
14 changes: 6 additions & 8 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ let expectA, expectA2, expectB, expectC, expectD, expectE;
test.before(async () => {
const mkDir = () => fs.mkdir(tmpDir);

await fs.rmdir(tmpDir, {recursive: true})
// @note Conditional check here since we have a relaxed 'package.json.engines.node' value,
// and `fs.rmdir` is being deprecated in later versions of node (node v18+).
// ----
await (fs.rm ? fs.rm : fs.rmdir)(tmpDir, {recursive: true})
.then(mkDir, mkDir)
.then(() => Promise.all([
'test/assets/expect_a.css',
Expand Down Expand Up @@ -314,12 +317,12 @@ test('should support processor return type `Promise<{css: string, icssExport: {}
t.true(rslt.includes(expectB));
});

test('should processor throw error', async t => {
test('should throw an error when processor returns an object type missing the `css` prop.', async t => {
await t.throwsAsync(async () => rollup({
input: 'test/fixtures/processor-error/index.js',
plugins: [
sass({
// @ts-ignore
// @ts-ignore - Ignoring incorrect type (for test).
processor: () => ({}),
options: sassOptions,
}),
Expand Down Expand Up @@ -475,8 +478,3 @@ test('When `sourcemap` is set, to `true`, adjacent source map file should be out
});
});
});

test.after(async (): Promise<any> => {
return fs.rmdir(tmpDir, {recursive: true})
.catch(error);
});

0 comments on commit c6e45f1

Please sign in to comment.