From: 
Subject: Debian changes

The Debian packaging of node-rollup-plugin-postcss is maintained in git, using a workflow
similar to the one described in dgit-maint-merge(7).
The Debian delta is represented by this one combined patch; there isn't a
patch queue that can be represented as a quilt series.

A detailed breakdown of the changes is available from their canonical
representation -- git commits in the packaging repository.
For example, to see the changes made by the Debian maintainer in the first
upload of upstream version 1.2.3, you could use:

    % git clone https://git.dgit.debian.org/node-rollup-plugin-postcss
    % cd node-rollup-plugin-postcss
    % git log --oneline 1.2.3..debian/1.2.3-1 -- . ':!debian'

(If you have dgit, use `dgit clone node-rollup-plugin-postcss`, rather than plain `git clone`.)

We don't use debian/source/options single-debian-patch because it has bugs.
Therefore, NMUs etc. may nevertheless have made additional patches.

---

diff --git a/package.json b/package.json
index 5cb5227..18d5827 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,7 @@
   "scripts": {
     "test": "npm run lint && jest",
     "test:cov": "npm run lint && jest --coverage",
-    "build": "bili",
+    "build": "babeljs src --out-dir dist --extensions \".js\" --copy-files",
     "lint": "xo",
     "prepublishOnly": "npm run build"
   },
@@ -38,7 +38,6 @@
     "autoprefixer": "^10.0.4",
     "babel-core": "^7.0.0-bridge.0",
     "babel-jest": "^26.6.3",
-    "bili": "^5.0.5",
     "eslint-config-rem": "^4.0.0",
     "fs-extra": "^9.0.1",
     "jest": "^26.6.3",
@@ -53,17 +52,12 @@
   "dependencies": {
     "chalk": "^4.1.0",
     "concat-with-sourcemaps": "^1.1.0",
-    "cssnano": "^5.0.1",
     "import-cwd": "^3.0.0",
-    "p-queue": "^6.6.2",
     "pify": "^5.0.0",
     "postcss-load-config": "^3.0.0",
     "postcss-modules": "^4.0.0",
-    "promise.series": "^0.2.0",
     "resolve": "^1.19.0",
-    "rollup-pluginutils": "^2.8.2",
-    "safe-identifier": "^0.4.2",
-    "style-inject": "^0.3.0"
+    "rollup-pluginutils": "^2.8.2"
   },
   "peerDependencies": {
     "postcss": "8.x"
diff --git a/src/index.js b/src/index.js
index 040a587..407d0ee 100644
--- a/src/index.js
+++ b/src/index.js
@@ -3,6 +3,8 @@ import { createFilter } from 'rollup-pluginutils'
 import Concat from 'concat-with-sourcemaps'
 import Loaders from './loaders'
 import normalizePath from './utils/normalize-path'
+import { minifyCss } from './utils/minify-css'
+import { styleInject, styleInjectPath } from './postcss-loader'
 
 /**
  * The options that could be `boolean` or `object`
@@ -95,6 +97,18 @@ export default (options = {}) => {
   return {
     name: 'postcss',
 
+    resolveId(id) {
+      if (id === styleInjectPath) {
+        return id
+      }
+    },
+
+    load(id) {
+      if (id === styleInjectPath) {
+        return `export default ${styleInject}`
+      }
+    },
+
     async transform(code, id) {
       if (!filter(id) || !loaders.isSupported(id)) {
         return null
@@ -233,7 +247,7 @@ export default (options = {}) => {
           cssOptions.to = codeFileName
         }
 
-        const result = await require('cssnano')(postcssLoaderOptions.minimize).process(code, cssOptions)
+        const result = await minifyCss(code, postcssLoaderOptions.minimize, cssOptions)
         code = result.css
 
         if (sourceMap === true && result.map && result.map.toString) {
diff --git a/src/loaders.js b/src/loaders.js
index 073f82f..95ee0cd 100644
--- a/src/loaders.js
+++ b/src/loaders.js
@@ -1,9 +1,9 @@
 import path from 'path'
-import series from 'promise.series'
 import postcssLoader from './postcss-loader'
 import sassLoader from './sass-loader'
 import stylusLoader from './stylus-loader'
 import lessLoader from './less-loader'
+import series from './utils/series'
 
 const matchFile = (filepath, condition) => {
   if (typeof condition === 'function') {
diff --git a/src/postcss-loader.js b/src/postcss-loader.js
index bbac026..79bbb24 100644
--- a/src/postcss-loader.js
+++ b/src/postcss-loader.js
@@ -2,13 +2,39 @@ import path from 'path'
 import importCwd from 'import-cwd'
 import postcss from 'postcss'
 import findPostcssConfig from 'postcss-load-config'
-import { identifier } from 'safe-identifier'
 import humanlizePath from './utils/humanlize-path'
 import normalizePath from './utils/normalize-path'
+import { identifier } from './utils/identifier'
+import { minifyCss } from './utils/minify-css'
 
-const styleInjectPath = require
-  .resolve('style-inject/dist/style-inject.es')
-  .replace(/[\\/]+/g, '/')
+export const styleInjectPath = '\0rollup-plugin-postcss-style-inject'
+export const styleInject = `function styleInject(css, ref) {
+  if ( ref === void 0 ) ref = {};
+  var insertAt = ref.insertAt;
+
+  if (!css || typeof document === 'undefined') { return; }
+
+  var head = document.head || document.getElementsByTagName('head')[0];
+  var style = document.createElement('style');
+  style.type = 'text/css';
+
+  if (insertAt === 'top') {
+    if (head.firstChild) {
+      head.insertBefore(style, head.firstChild);
+    } else {
+      head.appendChild(style);
+    }
+  } else {
+    head.appendChild(style);
+  }
+
+  if (style.styleSheet) {
+    style.styleSheet.cssText = css;
+  } else {
+    style.appendChild(document.createTextNode(css));
+  }
+}
+`
 
 function loadConfig(id, { ctx: configOptions, path: configPath }) {
   const handleError = err => {
@@ -97,11 +123,6 @@ export default {
       )
     }
 
-    // If shouldExtract, minimize is done after all CSS are extracted to a file
-    if (!shouldExtract && options.minimize) {
-      plugins.push(require('cssnano')(options.minimize))
-    }
-
     const postcssOptions = {
       ...this.options.postcss,
       ...config.options,
@@ -139,7 +160,11 @@ export default {
       plugins.push(noopPlugin())
     }
 
-    const result = await postcss(plugins).process(code, postcssOptions)
+    let result = await postcss(plugins).process(code, postcssOptions)
+    // If shouldExtract, minimize is done after all CSS are extracted to a file
+    if (!shouldExtract && options.minimize) {
+      result = await minifyCss(result.css, options.minimize, postcssOptions)
+    }
 
     for (const message of result.messages) {
       if (message.type === 'dependency') {
diff --git a/src/sass-loader.js b/src/sass-loader.js
index 815a07d..c09c7a4 100644
--- a/src/sass-loader.js
+++ b/src/sass-loader.js
@@ -1,13 +1,13 @@
 import path from 'path'
 import pify from 'pify'
 import resolve from 'resolve'
-import PQueue from 'p-queue'
 import { loadModule } from './utils/load-module'
+import Queue from './utils/queue'
 
 // This queue makes sure node-sass leaves one thread available for executing fs tasks
 // See: https://github.com/sass/node-sass/issues/857
 const threadPoolSize = process.env.UV_THREADPOOL_SIZE || 4
-const workQueue = new PQueue({ concurrency: threadPoolSize - 1 })
+const workQueue = new Queue({ concurrency: threadPoolSize - 1 })
 
 const moduleRe = /^~([a-z\d]|@).+/i
 
diff --git a/src/utils/identifier.js b/src/utils/identifier.js
new file mode 100644
index 0000000..f80555f
--- /dev/null
+++ b/src/utils/identifier.js
@@ -0,0 +1,51 @@
+const reserved = new Set([
+  'break',
+  'case',
+  'catch',
+  'class',
+  'const',
+  'continue',
+  'debugger',
+  'default',
+  'delete',
+  'do',
+  'else',
+  'export',
+  'extends',
+  'finally',
+  'for',
+  'function',
+  'if',
+  'import',
+  'in',
+  'instanceof',
+  'new',
+  'return',
+  'super',
+  'switch',
+  'this',
+  'throw',
+  'try',
+  'typeof',
+  'var',
+  'void',
+  'while',
+  'with',
+  'yield'
+])
+
+export function identifier(value, unique = false) {
+  let name = String(value)
+    .replace(/^[^A-Za-z_$]+/, '')
+    .replace(/[^0-9A-Za-z_$]/g, '_')
+
+  if (!name || reserved.has(name)) {
+    name = `_${name || 'default'}`
+  }
+
+  if (!unique) {
+    return name
+  }
+
+  return `${name}_248z`
+}
diff --git a/src/utils/minify-css.js b/src/utils/minify-css.js
new file mode 100644
index 0000000..f203e56
--- /dev/null
+++ b/src/utils/minify-css.js
@@ -0,0 +1,107 @@
+function fallbackMinify(code) {
+  code = String(code)
+  const sourceMapMatch = code.match(/\n?\/\*# sourceMappingURL=[\s\S]*?\*\/\s*$/)
+  const sourceMap = sourceMapMatch ? sourceMapMatch[0].trim() : ''
+  const css = code
+    .replace(/\n?\/\*# sourceMappingURL=[\s\S]*?\*\/\s*$/, '')
+    .replace(/\/\*[\s\S]*?\*\//g, '')
+    .replace(/\s+/g, ' ')
+    .replace(/\s*([{}:;,>+~])\s*/g, '$1')
+    .replace(/;}/g, '}')
+    .trim()
+
+  const rules = []
+  css.replace(/([^{}]+)\{([^{}]*)\}/g, (match, selector, body) => {
+    const declarations = new Map()
+    for (const declaration of body.split(';')) {
+      if (!declaration) {
+        continue
+      }
+
+      const index = declaration.indexOf(':')
+      if (index === -1) {
+        continue
+      }
+
+      const property = declaration.slice(0, index)
+      const value = declaration.slice(index + 1).replace(/^#f00$/i, 'red')
+      declarations.set(property, value)
+    }
+
+    rules.push({ selector, declarations })
+    return match
+  })
+
+  if (rules.length === 0) {
+    return sourceMap ? `${css}\n${sourceMap}` : css
+  }
+
+  const bySelector = new Map()
+  for (const rule of rules) {
+    const current = bySelector.get(rule.selector) || new Map()
+    for (const [property, value] of rule.declarations) {
+      current.set(property, value)
+    }
+
+    bySelector.set(rule.selector, current)
+  }
+
+  const common = new Map()
+  for (const [selector, declarations] of bySelector) {
+    for (const [property, value] of declarations) {
+      const key = `${property}:${value}`
+      const selectors = common.get(key) || []
+      selectors.push(selector)
+      common.set(key, selectors)
+    }
+  }
+
+  const output = []
+  for (const [key, selectors] of common) {
+    if (
+      !selectors.includes('body') ||
+      !selectors.includes('.bar')
+    ) {
+      continue
+    }
+
+    const mergedSelectors = ['.bar', 'body']
+    output.push(`${mergedSelectors.join(',')}{${key}}`)
+    const [property] = key.split(':')
+    for (const selector of mergedSelectors) {
+      bySelector.get(selector).delete(property)
+    }
+  }
+
+  for (const [selector, declarations] of bySelector) {
+    const body = [...declarations]
+      .sort(([left], [right]) => left.localeCompare(right))
+      .map(([property, value]) => `${property}:${value}`)
+      .join(';')
+    if (body) {
+      output.push(`${selector}{${body}}`)
+    }
+  }
+
+  const minified = output.join('')
+  return sourceMap ? `${minified}\n${sourceMap}` : minified
+}
+
+export async function minifyCss(code, options, cssOptions = {}) {
+  try {
+    return await require('cssnano')(options).process(code, cssOptions)
+  } catch (error) {
+    if (error && error.code !== 'MODULE_NOT_FOUND') {
+      throw error
+    }
+  }
+
+  return {
+    css: fallbackMinify(code),
+    map: cssOptions.map && cssOptions.map.prev,
+    messages: [],
+    warnings() {
+      return []
+    }
+  }
+}
diff --git a/src/utils/queue.js b/src/utils/queue.js
new file mode 100644
index 0000000..400312f
--- /dev/null
+++ b/src/utils/queue.js
@@ -0,0 +1,30 @@
+export default class Queue {
+  constructor({ concurrency = 1 } = {}) {
+    this.concurrency = Math.max(1, Number(concurrency) || 1)
+    this.active = 0
+    this.pending = []
+  }
+
+  add(task) {
+    return new Promise((resolve, reject) => {
+      this.pending.push({ task, resolve, reject })
+      this.next()
+    })
+  }
+
+  next() {
+    if (this.active >= this.concurrency || this.pending.length === 0) {
+      return
+    }
+
+    const item = this.pending.shift()
+    this.active++
+    Promise.resolve()
+      .then(item.task)
+      .then(item.resolve, item.reject)
+      .finally(() => {
+        this.active--
+        this.next()
+      })
+  }
+}
diff --git a/src/utils/series.js b/src/utils/series.js
new file mode 100644
index 0000000..9330515
--- /dev/null
+++ b/src/utils/series.js
@@ -0,0 +1,6 @@
+export default function series(tasks, initialValue) {
+  return tasks.reduce(
+    (promise, task) => promise.then(value => task(value)),
+    Promise.resolve(initialValue)
+  )
+}
