Skip to content

Commit

Permalink
fix: respect NODE_ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
Anidetrix committed Mar 29, 2020
1 parent 369279a commit 7a600c3
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = api => {
api.cache.invalidate(() => process.env.NODE_ENV === "production");

const presets = [["@babel/preset-env", { targets: { node: "10" } }]];
const presets = [["@babel/preset-env", { modules: false, targets: { node: "10" } }]];
const plugins = [["@babel/plugin-transform-runtime", { useESModules: true }]];

if (api.env("test")) presets[0][1].modules = "commonjs";
Expand Down
8 changes: 4 additions & 4 deletions docs/globals.html
Original file line number Diff line number Diff line change
Expand Up @@ -3874,7 +3874,7 @@ <h3>fixture</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L31">test/index.test.ts:31</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L29">test/index.test.ts:29</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down Expand Up @@ -4528,7 +4528,7 @@ <h3>validate</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L67">test/index.test.ts:67</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L65">test/index.test.ts:65</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down Expand Up @@ -4565,7 +4565,7 @@ <h3>validate<wbr>Many</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L99">test/index.test.ts:99</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L97">test/index.test.ts:97</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -4591,7 +4591,7 @@ <h3>write</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L35">test/index.test.ts:35</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L33">test/index.test.ts:33</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down
8 changes: 4 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3875,7 +3875,7 @@ <h3>fixture</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L31">test/index.test.ts:31</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L29">test/index.test.ts:29</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down Expand Up @@ -4529,7 +4529,7 @@ <h3>validate</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L67">test/index.test.ts:67</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L65">test/index.test.ts:65</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down Expand Up @@ -4566,7 +4566,7 @@ <h3>validate<wbr>Many</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L99">test/index.test.ts:99</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L97">test/index.test.ts:97</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -4592,7 +4592,7 @@ <h3>write</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L35">test/index.test.ts:35</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L33">test/index.test.ts:33</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down
8 changes: 4 additions & 4 deletions docs/interfaces/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -2780,7 +2780,7 @@ <h3>input</h3>
<aside class="tsd-sources">
<p>Inherited from <a href="writedata.html">WriteData</a>.<a href="writedata.html#input">input</a></p>
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L12">test/index.test.ts:12</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L10">test/index.test.ts:10</a></li>
</ul>
</aside>
</section>
Expand All @@ -2791,7 +2791,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> options</h3>
<aside class="tsd-sources">
<p>Inherited from <a href="writedata.html">WriteData</a>.<a href="writedata.html#options">options</a></p>
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L14">test/index.test.ts:14</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L12">test/index.test.ts:12</a></li>
</ul>
</aside>
</section>
Expand All @@ -2802,7 +2802,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> out<wbr>Dir</h3>
<aside class="tsd-sources">
<p>Inherited from <a href="writedata.html">WriteData</a>.<a href="writedata.html#outdir">outDir</a></p>
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L13">test/index.test.ts:13</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L11">test/index.test.ts:11</a></li>
</ul>
</aside>
</section>
Expand All @@ -2812,7 +2812,7 @@ <h3>title</h3>
<div class="tsd-signature tsd-kind-icon">title<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L18">test/index.test.ts:18</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L16">test/index.test.ts:16</a></li>
</ul>
</aside>
</section>
Expand Down
12 changes: 6 additions & 6 deletions docs/interfaces/testdata.html
Original file line number Diff line number Diff line change
Expand Up @@ -2782,7 +2782,7 @@ <h3>css</h3>
<div class="tsd-signature tsd-kind-icon">css<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> =&gt; </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">&gt;</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L23">test/index.test.ts:23</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L21">test/index.test.ts:21</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
Expand All @@ -2807,7 +2807,7 @@ <h3>is<wbr>Css</h3>
<div class="tsd-signature tsd-kind-icon">is<wbr>Css<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> =&gt; </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">&gt;</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L25">test/index.test.ts:25</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L23">test/index.test.ts:23</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
Expand All @@ -2832,7 +2832,7 @@ <h3>is<wbr>File</h3>
<div class="tsd-signature tsd-kind-icon">is<wbr>File<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span>filename<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> =&gt; </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">&gt;</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L27">test/index.test.ts:27</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L25">test/index.test.ts:25</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
Expand Down Expand Up @@ -2863,7 +2863,7 @@ <h3>is<wbr>Map</h3>
<div class="tsd-signature tsd-kind-icon">is<wbr>Map<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> =&gt; </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">&gt;</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L26">test/index.test.ts:26</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L24">test/index.test.ts:24</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
Expand All @@ -2888,7 +2888,7 @@ <h3>js</h3>
<div class="tsd-signature tsd-kind-icon">js<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> =&gt; </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">&gt;</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L22">test/index.test.ts:22</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L20">test/index.test.ts:20</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
Expand All @@ -2913,7 +2913,7 @@ <h3>map</h3>
<div class="tsd-signature tsd-kind-icon">map<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> =&gt; </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">&gt;</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L24">test/index.test.ts:24</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L22">test/index.test.ts:22</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
Expand Down
6 changes: 3 additions & 3 deletions docs/interfaces/writedata.html
Original file line number Diff line number Diff line change
Expand Up @@ -2775,7 +2775,7 @@ <h3>input</h3>
<div class="tsd-signature tsd-kind-icon">input<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L12">test/index.test.ts:12</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L10">test/index.test.ts:10</a></li>
</ul>
</aside>
</section>
Expand All @@ -2785,7 +2785,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> options</h3>
<div class="tsd-signature tsd-kind-icon">options<span class="tsd-signature-symbol">:</span> <a href="options.html" class="tsd-signature-type">Options</a></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L14">test/index.test.ts:14</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L12">test/index.test.ts:12</a></li>
</ul>
</aside>
</section>
Expand All @@ -2795,7 +2795,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> out<wbr>Dir</h3>
<div class="tsd-signature tsd-kind-icon">out<wbr>Dir<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">undefined</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L13">test/index.test.ts:13</a></li>
<li>Defined in <a href="https://github.com/Anidetrix/rollup-plugin-styles/blob/master/test/index.test.ts#L11">test/index.test.ts:11</a></li>
</ul>
</aside>
</section>
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
"dist"
],
"scripts": {
"build": "rollup -c",
"build": "rollup -c --environment NODE_ENV:development",
"build:prod": "rollup -c --environment NODE_ENV:production",
"docgen": "typedoc",
"format": "prettier -l --write .",
"lint": "npm run format && eslint --ext .ts,.js .",
"lint:fix": "npm run format && eslint --ext .ts,.js --fix .",
"test": "npm run lint:fix && jest",
"test:cov": "npm run lint:fix && jest --coverage",
"commit": "commit",
"prepublishOnly": "shx rm -rf dist && npm run build && shx cp -r src/typings runtime dist && shx rm -rf \"dist/**/.eslintrc*\""
"prepublishOnly": "shx rm -rf dist && npm run build:prod && shx cp -r src/typings runtime dist && shx rm -rf \"dist/**/.eslintrc*\""
},
"repository": {
"type": "git",
Expand Down
5 changes: 3 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { terser } from "rollup-plugin-terser";

import pkg from "./package.json";

const prod = process.env.NODE_ENV === "production";
export default [
// Bundle
{
Expand All @@ -20,14 +21,14 @@ export default [
plugins: [
autoExternal(),
json(),
replace({ "process.env.STYLES_TEST": false }),
replace({ "process.env.NODE_ENV": JSON.stringify(prod ? "production" : "development") }),
resolve({
preferBuiltins: true,
extensions: [".ts", ".mjs", ".js", ".json"],
}),
commonjs(),
ts({ transpiler: "babel" }),
terser(),
prod && terser(),
],
},
// Declaration
Expand Down
10 changes: 6 additions & 4 deletions src/loaders/postcss/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ const loader: Loader<PostCSSLoaderOptions> = {
...postcssModules({
// Skip hash while testing since CSS content would differ on Windows and Linux
// due to different line endings.
generateScopedName: process.env.STYLES_TEST
? "[name]_[local]"
: "[name]_[local]__[hash:8]",
generateScopedName:
process.env.NODE_ENV === "test" ? "[name]_[local]" : "[name]_[local]__[hash:8]",
failOnWrongOrder: true,
...modulesOptions,
}),
Expand Down Expand Up @@ -190,7 +189,10 @@ const loader: Loader<PostCSSLoaderOptions> = {
const injectorName = safeId("injector");
const injectorPath = normalizePath(
await resolveAsync("./inject-css", {
basedir: path.join(process.env.STYLES_TEST ? process.cwd() : __dirname, "runtime"),
basedir: path.join(
process.env.NODE_ENV === "test" ? process.cwd() : __dirname,
"runtime",
),
}),
);
const injectorData =
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/sass/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const loader: Loader<SASSLoaderOptions> = {

let fiber: FiberConstructor | undefined;
// Disable `fibers` for testing, it doesn't work
if (sassType == "sass" && !process.env.STYLES_TEST) fiber = await loadModule("fibers");
if (sassType == "sass" && process.env.NODE_ENV !== "test") fiber = await loadModule("fibers");

return workQueue.add<Payload>(
async (): Promise<Payload> => {
Expand Down
2 changes: 0 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import commonjs from "@rollup/plugin-commonjs";
import postcss from "../src";
import { Options } from "../src/types";

process.env.STYLES_TEST = "true";

// Types
interface WriteData {
input: string;
Expand Down
2 changes: 0 additions & 2 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import path from "path";
import loadModule from "../src/utils/load-module";
import { getInlineMap, getExtractedMap, stripMap, MapModifier } from "../src/utils/sourcemap-utils";

process.env.STYLES_TEST = "true";

describe("load-module", () => {
test("wrong path", async () => {
const wrong = await loadModule("totallyWRONGPATH/here");
Expand Down

0 comments on commit 7a600c3

Please sign in to comment.