-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emit a deprecation warning when loaded as a default export (#230)
See #229
- Loading branch information
Showing
6 changed files
with
195 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import * as sass from './index.js'; | ||
|
||
export const compile = sass.compile; | ||
export const compileAsync = sass.compileAsync; | ||
export const compileString = sass.compileString; | ||
export const compileStringAsync = sass.compileStringAsync; | ||
export const Logger = sass.Logger; | ||
export const SassArgumentList = sass.SassArgumentList; | ||
export const SassBoolean = sass.SassBoolean; | ||
export const SassColor = sass.SassColor; | ||
export const SassFunction = sass.SassFunction; | ||
export const SassList = sass.SassList; | ||
export const SassMap = sass.SassMap; | ||
export const SassNumber = sass.SassNumber; | ||
export const SassString = sass.SassString; | ||
export const Value = sass.Value; | ||
export const CustomFunction = sass.CustomFunction; | ||
export const ListSeparator = sass.ListSeparator; | ||
export const sassFalse = sass.sassFalse; | ||
export const sassNull = sass.sassNull; | ||
export const sassTrue = sass.sassTrue; | ||
export const Exception = sass.Exception; | ||
export const PromiseOr = sass.PromiseOr; | ||
export const info = sass.info; | ||
export const render = sass.render; | ||
export const renderSync = sass.renderSync; | ||
export const TRUE = sass.TRUE; | ||
export const FALSE = sass.FALSE; | ||
export const NULL = sass.NULL; | ||
export const types = sass.types; | ||
|
||
let printedDefaultExportDeprecation = false; | ||
function defaultExportDeprecation() { | ||
if (printedDefaultExportDeprecation) return; | ||
printedDefaultExportDeprecation = true; | ||
console.error( | ||
"`import sass from 'sass'` is deprecated.\n" + | ||
"Please use `import * as sass from 'sass'` instead."); | ||
} | ||
|
||
export default { | ||
get compile() { | ||
defaultExportDeprecation(); | ||
return sass.compile; | ||
}, | ||
get compileAsync() { | ||
defaultExportDeprecation(); | ||
return sass.compileAsync; | ||
}, | ||
get compileString() { | ||
defaultExportDeprecation(); | ||
return sass.compileString; | ||
}, | ||
get compileStringAsync() { | ||
defaultExportDeprecation(); | ||
return sass.compileStringAsync; | ||
}, | ||
get Logger() { | ||
defaultExportDeprecation(); | ||
return sass.Logger; | ||
}, | ||
get SassArgumentList() { | ||
defaultExportDeprecation(); | ||
return sass.SassArgumentList; | ||
}, | ||
get SassBoolean() { | ||
defaultExportDeprecation(); | ||
return sass.SassBoolean; | ||
}, | ||
get SassColor() { | ||
defaultExportDeprecation(); | ||
return sass.SassColor; | ||
}, | ||
get SassFunction() { | ||
defaultExportDeprecation(); | ||
return sass.SassFunction; | ||
}, | ||
get SassList() { | ||
defaultExportDeprecation(); | ||
return sass.SassList; | ||
}, | ||
get SassMap() { | ||
defaultExportDeprecation(); | ||
return sass.SassMap; | ||
}, | ||
get SassNumber() { | ||
defaultExportDeprecation(); | ||
return sass.SassNumber; | ||
}, | ||
get SassString() { | ||
defaultExportDeprecation(); | ||
return sass.SassString; | ||
}, | ||
get Value() { | ||
defaultExportDeprecation(); | ||
return sass.Value; | ||
}, | ||
get CustomFunction() { | ||
defaultExportDeprecation(); | ||
return sass.CustomFunction; | ||
}, | ||
get ListSeparator() { | ||
defaultExportDeprecation(); | ||
return sass.ListSeparator; | ||
}, | ||
get sassFalse() { | ||
defaultExportDeprecation(); | ||
return sass.sassFalse; | ||
}, | ||
get sassNull() { | ||
defaultExportDeprecation(); | ||
return sass.sassNull; | ||
}, | ||
get sassTrue() { | ||
defaultExportDeprecation(); | ||
return sass.sassTrue; | ||
}, | ||
get Exception() { | ||
defaultExportDeprecation(); | ||
return sass.Exception; | ||
}, | ||
get PromiseOr() { | ||
defaultExportDeprecation(); | ||
return sass.PromiseOr; | ||
}, | ||
get info() { | ||
defaultExportDeprecation(); | ||
return sass.info; | ||
}, | ||
get render() { | ||
defaultExportDeprecation(); | ||
return sass.render; | ||
}, | ||
get renderSync() { | ||
defaultExportDeprecation(); | ||
return sass.renderSync; | ||
}, | ||
get TRUE() { | ||
defaultExportDeprecation(); | ||
return sass.TRUE; | ||
}, | ||
get FALSE() { | ||
defaultExportDeprecation(); | ||
return sass.FALSE; | ||
}, | ||
get NULL() { | ||
defaultExportDeprecation(); | ||
return sass.NULL; | ||
}, | ||
get types() { | ||
defaultExportDeprecation(); | ||
return sass.types; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2023 Google LLC. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import * as fs from 'fs'; | ||
|
||
// Note: this file isn't .test.ts specifically because we _don't_ want Jest to | ||
// handle it, because Jest chokes on dynamic imports of literal ESM modules. | ||
|
||
// This file should only be run _after_ `npm run compile`. | ||
if (!fs.existsSync('dist/package.json')) { | ||
throw new Error('after-compile.test.ts must be run after `npm run compile`.'); | ||
} | ||
|
||
// Load these dynamically so we have a better error mesage if `npm run compile` | ||
// hasn't been run. | ||
const cjs = await import('../dist/lib/index.js'); | ||
const esm = await import('../dist/lib/index.mjs'); | ||
|
||
for (const [name, value] of Object.entries(cjs)) { | ||
if (name === '__esModule' || name === 'default') continue; | ||
if (!esm[name]) { | ||
throw new Error(`ESM module is missing export ${name}.`); | ||
} else if (esm[name] !== value) { | ||
throw new Error(`ESM ${name} isn't the same as CJS.`); | ||
} | ||
|
||
if (!esm.default[name]) { | ||
throw new Error(`ESM default export is missing export ${name}.`); | ||
} else if (esm.default[name] !== value) { | ||
throw new Error(`ESM default export ${name} isn't the same as CJS.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters