From 63bc959bdabcdea5b3855232bce4fe78be6da26f Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Sun, 3 May 2020 08:33:23 +0300 Subject: [PATCH] fix(injector): pass selector instead of element as container ...which seems impossible from nodejs environment, missed that somehow --- __tests__/__snapshots__/index.test.ts.snap | 88 +++++++++++----------- package.json | 2 +- pnpm-lock.yaml | 25 +++--- runtime/inject-css.js | 4 +- src/types.ts | 4 +- 5 files changed, 64 insertions(+), 59 deletions(-) diff --git a/__tests__/__snapshots__/index.test.ts.snap b/__tests__/__snapshots__/index.test.ts.snap index 453966ff..24f83245 100644 --- a/__tests__/__snapshots__/index.test.ts.snap +++ b/__tests__/__snapshots__/index.test.ts.snap @@ -11,7 +11,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_7aa87f99 (css, options) { @@ -23,7 +23,7 @@ function injector_7aa87f99 (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -80,7 +80,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_5856ff83 (css, options) { @@ -92,7 +92,7 @@ function injector_5856ff83 (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -211,7 +211,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_9d0ece4d (css, options) { @@ -223,7 +223,7 @@ function injector_9d0ece4d (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -297,7 +297,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_b33bb41a (css, options) { @@ -309,7 +309,7 @@ function injector_b33bb41a (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -784,7 +784,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_9d0ece4d (css, options) { @@ -796,7 +796,7 @@ function injector_9d0ece4d (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -870,7 +870,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_c27d7fc7 (css, options) { @@ -882,7 +882,7 @@ function injector_c27d7fc7 (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -980,7 +980,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_9d0ece4d (css, options) { @@ -992,7 +992,7 @@ function injector_9d0ece4d (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -1066,7 +1066,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_f247f96b (css, options) { @@ -1078,7 +1078,7 @@ function injector_f247f96b (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -1295,7 +1295,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_2ae7f8dc (css, options) { @@ -1307,7 +1307,7 @@ function injector_2ae7f8dc (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -1375,7 +1375,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_2ae7f8dc (css, options) { @@ -1387,7 +1387,7 @@ function injector_2ae7f8dc (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -1455,7 +1455,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_b11e0f66 (css, options) { @@ -1467,7 +1467,7 @@ function injector_b11e0f66 (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -1540,7 +1540,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_b11e0f66 (css, options) { @@ -1552,7 +1552,7 @@ function injector_b11e0f66 (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -1625,7 +1625,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_e8b4c2e2 (css, options) { @@ -1637,7 +1637,7 @@ function injector_e8b4c2e2 (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -1700,7 +1700,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_2401b93b (css, options) { @@ -1712,7 +1712,7 @@ function injector_2401b93b (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -1787,7 +1787,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_00f7b4db (css, options) { @@ -1799,7 +1799,7 @@ function injector_00f7b4db (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -1856,7 +1856,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_b66c0a2f (css, options) { @@ -1868,7 +1868,7 @@ function injector_b66c0a2f (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -1925,7 +1925,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_7e51928e (css, options) { @@ -1937,7 +1937,7 @@ function injector_7e51928e (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -1994,7 +1994,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_704767c1 (css, options) { @@ -2006,7 +2006,7 @@ function injector_704767c1 (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -2066,7 +2066,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_b66c0a2f (css, options) { @@ -2078,7 +2078,7 @@ function injector_b66c0a2f (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -2135,7 +2135,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_ea92f1f2 (css, options) { @@ -2147,7 +2147,7 @@ function injector_ea92f1f2 (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -2204,7 +2204,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_9d0ece4d (css, options) { @@ -2216,7 +2216,7 @@ function injector_9d0ece4d (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { @@ -2290,7 +2290,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ function injector_9d0ece4d (css, options) { @@ -2302,7 +2302,7 @@ function injector_9d0ece4d (css, options) { var container = typeof options.container !== \\"undefined\\" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName(\\"head\\")[0]; function createStyleTag() { diff --git a/package.json b/package.json index dd63cd92..60a4d18b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ }, "dependencies": { "@babel/runtime": "^7.9.6", - "@rollup/pluginutils": "^3.0.9", + "@rollup/pluginutils": "^3.0.10", "concat-with-sourcemaps": "^1.1.0", "cssnano": "^4.1.10", "icss-utils": "^4.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3413e66c..7d40c8f4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,6 +1,6 @@ dependencies: '@babel/runtime': 7.9.6 - '@rollup/pluginutils': 3.0.9_rollup@2.7.6 + '@rollup/pluginutils': 3.0.10_rollup@2.7.6 concat-with-sourcemaps: 1.1.0 cssnano: 4.1.10 icss-utils: 4.1.1 @@ -1436,7 +1436,7 @@ packages: dependencies: '@babel/core': 7.9.6 '@babel/helper-module-imports': 7.8.3 - '@rollup/pluginutils': 3.0.9_rollup@2.7.6 + '@rollup/pluginutils': 3.0.10_rollup@2.7.6 rollup: 2.7.6 dev: true engines: @@ -1448,7 +1448,7 @@ packages: integrity: sha512-YpVnwdUeVj/fDFN75Y3CAzJTMYNcqbH05SJs551wqj+BSwLT9pS3dqJrVDPYl3eH4OrI8ueiEseX5VgUn+0HLA== /@rollup/plugin-commonjs/11.1.0_rollup@2.7.6: dependencies: - '@rollup/pluginutils': 3.0.9_rollup@2.7.6 + '@rollup/pluginutils': 3.0.10_rollup@2.7.6 commondir: 1.0.1 estree-walker: 1.0.1 glob: 7.1.6 @@ -1465,7 +1465,7 @@ packages: integrity: sha512-Ycr12N3ZPN96Fw2STurD21jMqzKwL9QuFhms3SD7KKRK7oaXUsBU9Zt0jL/rOPHiPYisI21/rXGO3jr9BnLHUA== /@rollup/plugin-json/4.0.3_rollup@2.7.6: dependencies: - '@rollup/pluginutils': 3.0.9_rollup@2.7.6 + '@rollup/pluginutils': 3.0.10_rollup@2.7.6 rollup: 2.7.6 dev: true peerDependencies: @@ -1474,7 +1474,7 @@ packages: integrity: sha512-QMUT0HZNf4CX17LMdwaslzlYHUKTYGuuk34yYIgZrNdu+pMEfqMS55gck7HEeHBKXHM4cz5Dg1OVwythDdbbuQ== /@rollup/plugin-node-resolve/7.1.3_rollup@2.7.6: dependencies: - '@rollup/pluginutils': 3.0.9_rollup@2.7.6 + '@rollup/pluginutils': 3.0.10_rollup@2.7.6 '@types/resolve': 0.0.8 builtin-modules: 3.1.0 is-module: 1.0.0 @@ -1489,7 +1489,7 @@ packages: integrity: sha512-RxtSL3XmdTAE2byxekYLnx+98kEUOrPHF/KRVjLH+DEIHy6kjIw7YINQzn+NXiH/NTrQLAwYs0GWB+csWygA9Q== /@rollup/plugin-typescript/4.1.1_be1e7a4464f555e2f1e270028e96222f: dependencies: - '@rollup/pluginutils': 3.0.9_rollup@2.7.6 + '@rollup/pluginutils': 3.0.10_rollup@2.7.6 resolve: 1.17.0 rollup: 2.7.6 tslib: 1.11.1 @@ -1503,18 +1503,18 @@ packages: typescript: '>=2.1.0' resolution: integrity: sha512-KYZCn1Iw9hZWkeEPqPs5YjlmvSjR7UdezVca8z0e8rm/29wU24UD9Y4IZHhnc9tm749hzsgBTiOUxA85gfShEQ== - /@rollup/pluginutils/3.0.9_rollup@2.7.6: + /@rollup/pluginutils/3.0.10_rollup@2.7.6: dependencies: '@types/estree': 0.0.39 estree-walker: 1.0.1 - micromatch: 4.0.2 + picomatch: 2.2.2 rollup: 2.7.6 engines: node: '>= 8.0.0' peerDependencies: rollup: ^1.20.0||^2.0.0 resolution: - integrity: sha512-TLZavlfPAZYI7v33wQh4mTP6zojne14yok3DNSLcjoG/Hirxfkonn6icP5rrNWRn8nZsirJBFFpijVOJzkUHDg== + integrity: sha512-d44M7t+PjmMrASHbhgpSbVgtL6EFyX7J4mYxwQ/c5eoaE6N2VgCgEcWVzNnwycIloti+/MpwFr8qfw+nRw00sw== /@samverschueren/stream-to-observable/0.3.0: dependencies: any-observable: 0.3.0 @@ -2418,6 +2418,7 @@ packages: /braces/3.0.2: dependencies: fill-range: 7.0.1 + dev: true engines: node: '>=8' resolution: @@ -4089,6 +4090,7 @@ packages: /fill-range/7.0.1: dependencies: to-regex-range: 5.0.1 + dev: true engines: node: '>=8' resolution: @@ -5047,6 +5049,7 @@ packages: resolution: integrity: sha1-JP1iAaR4LPUFYcgQJ2r8fRLXEZU= /is-number/7.0.0: + dev: true engines: node: '>=0.12.0' resolution: @@ -6287,6 +6290,7 @@ packages: dependencies: braces: 3.0.2 picomatch: 2.2.2 + dev: true engines: node: '>=8' resolution: @@ -9212,6 +9216,7 @@ packages: /to-regex-range/5.0.1: dependencies: is-number: 7.0.0 + dev: true engines: node: '>=8.0' resolution: @@ -9885,7 +9890,7 @@ specifiers: '@rollup/plugin-json': ^4.0.3 '@rollup/plugin-node-resolve': ^7.1.3 '@rollup/plugin-typescript': ^4.1.1 - '@rollup/pluginutils': ^3.0.9 + '@rollup/pluginutils': ^3.0.10 '@semantic-release/changelog': ^5.0.1 '@semantic-release/git': ^9.0.0 '@types/cssnano': ^4.0.0 diff --git a/runtime/inject-css.js b/runtime/inject-css.js index 0bb45f85..594a295d 100644 --- a/runtime/inject-css.js +++ b/runtime/inject-css.js @@ -8,7 +8,7 @@ var styleTags = []; * @param {object} [options={}] * @param {boolean} [options.prepend] * @param {boolean} [options.singleTag] - * @param {HTMLElement} [options.container] + * @param {string} [options.container] * @returns {void} */ export default function (css, options) { @@ -20,7 +20,7 @@ export default function (css, options) { var container = typeof options.container !== "undefined" - ? options.container + ? document.querySelector(options.container) : document.getElementsByTagName("head")[0]; function createStyleTag() { diff --git a/src/types.ts b/src/types.ts index 661d4c3a..4ee7bf84 100644 --- a/src/types.ts +++ b/src/types.ts @@ -199,9 +199,9 @@ export type InjectOptions = { singleTag?: boolean; /** * Container for `