diff --git a/ember-scoped-css/.eslintignore b/ember-scoped-css/.eslintignore new file mode 100644 index 00000000..e69140be --- /dev/null +++ b/ember-scoped-css/.eslintignore @@ -0,0 +1,8 @@ +# unconventional js +/blueprints/*/files/ + +# compiled output +/dist/ + +# misc +/coverage/ diff --git a/ember-scoped-css/.eslintrc.cjs b/ember-scoped-css/.eslintrc.cjs new file mode 100644 index 00000000..9ccd640d --- /dev/null +++ b/ember-scoped-css/.eslintrc.cjs @@ -0,0 +1,37 @@ +'use strict'; + +module.exports = { + root: true, + parser: 'babel-eslint', + parserOptions: { + ecmaVersion: 2020, + sourceType: 'module', + ecmaFeatures: { + modules: true, + }, + }, + plugins: ['node'], + extends: [ + 'eslint:recommended', + 'plugin:node/recommended-module' + ], + env: { + browser: false, + node: true, + }, + rules: { + }, + overrides: [ + { + files: [ + './test/**/*.js', + ], + env: { + mocha: true, + }, + rules: { + 'node/no-unpublished-import': 0, + } + }, + ], +}; diff --git a/ember-scoped-css/package.json b/ember-scoped-css/package.json index 267009f4..664cfdbd 100644 --- a/ember-scoped-css/package.json +++ b/ember-scoped-css/package.json @@ -20,7 +20,7 @@ "scripts": { "prepare": "npm run esbuild", "test": "mocha", - "lint": "", + "lint": "eslint .", "esbuild": "esbuild src/app-css-loader.js src/app-dependency-loader.js --bundle --outdir=dist --platform=node --out-extension:.js=.cjs" }, "keywords": [], @@ -40,9 +40,13 @@ "rollup": "^2.67.0", "unplugin": "^1.0.1" }, + "peerDependencies": { + "webpack": "^5.0.0" + }, "devDependencies": { "chai": "^4.3.7", "esbuild": "^0.17.17", + "eslint": "^8.38.0", "mocha": "^10.2.0", "sinon": "^15.0.1", "webpack": "^5.75.0" diff --git a/ember-scoped-css/src/addon-css-rollup.js b/ember-scoped-css/src/addon-css-rollup.js index 2bfb5137..85bd7926 100644 --- a/ember-scoped-css/src/addon-css-rollup.js +++ b/ember-scoped-css/src/addon-css-rollup.js @@ -1,11 +1,5 @@ import path from 'path'; -import getPostfix from './getPostfix.js'; -import rewriteCss from './rewriteCss.js'; import { readFile } from 'fs/promises'; -import fsExists from './fsExists.js'; -import findCssInJs from './findCssInJs.js'; -import getImportedCssFiles from './getImportedCssFiles.js'; -import recast from 'recast'; export default function () { return { diff --git a/ember-scoped-css/src/addon-hbs-rollup.js b/ember-scoped-css/src/addon-hbs-rollup.js index 9e6ba904..8710f31c 100644 --- a/ember-scoped-css/src/addon-hbs-rollup.js +++ b/ember-scoped-css/src/addon-hbs-rollup.js @@ -5,7 +5,7 @@ import getClassesTagsFromCss from './getClassesTagsFromCss.js'; import rewriteHbs from './rewriteHbs.js'; import fsExists from './fsExists.js'; -export default function rollupCssColocation(options = {}) { +export default function rollupCssColocation() { return { name: 'addon-hbs-rollup', diff --git a/ember-scoped-css/src/addon-js-unplugin.js b/ember-scoped-css/src/addon-js-unplugin.js index b9a6e447..9698dc47 100644 --- a/ember-scoped-css/src/addon-js-unplugin.js +++ b/ember-scoped-css/src/addon-js-unplugin.js @@ -9,7 +9,7 @@ import fsExists from './fsExists.js'; import findCssInJs from './findCssInJs.js'; import recast from 'recast'; -export default createUnplugin((options) => { +export default createUnplugin(() => { return { name: 'addon-js-unplugin', diff --git a/ember-scoped-css/src/app-css-livereload-loader.js b/ember-scoped-css/src/app-css-livereload-loader.js index 12f7aa3e..d734af1e 100644 --- a/ember-scoped-css/src/app-css-livereload-loader.js +++ b/ember-scoped-css/src/app-css-livereload-loader.js @@ -1,11 +1,10 @@ import { createUnplugin } from 'unplugin'; import path from 'path'; -import { readFile, writeFile } from 'fs/promises'; +import { readFile } from 'fs/promises'; import { Compilation } from 'webpack'; import getPostfix from './getPostfix.js'; -import cheerio from 'cheerio'; -export default createUnplugin(({ appDir, loaders, htmlEntrypointInfo }) => { +export default createUnplugin(({ loaders, htmlEntrypointInfo }) => { return { name: 'app-css-livereload-loader', @@ -77,7 +76,7 @@ export default createUnplugin(({ appDir, loaders, htmlEntrypointInfo }) => { if (!cssAssets.length) { return; } - let linkAdded = false; + // let linkAdded = false; const document = htmlEntrypointInfo.htmlEntryPoint.dom.window.document; @@ -92,7 +91,7 @@ export default createUnplugin(({ appDir, loaders, htmlEntrypointInfo }) => { link.rel = 'stylesheet'; link.href = '/' + asset; head.appendChild(link); - linkAdded = true; + // linkAdded = true; } } diff --git a/ember-scoped-css/src/app-css-loader.js b/ember-scoped-css/src/app-css-loader.js index 192d3dc7..93bb0ff6 100644 --- a/ember-scoped-css/src/app-css-loader.js +++ b/ember-scoped-css/src/app-css-loader.js @@ -1,5 +1,5 @@ // import { createUnplugin } from 'unplugin'; -import { basename, join } from 'path'; +import { basename } from 'path'; import fsExists from './fsExists.js'; import getPostfix from './getPostfix.js'; import rewriteCss from './rewriteCss.js'; diff --git a/ember-scoped-css/src/app-css-unplugin.js b/ember-scoped-css/src/app-css-unplugin.js index cee21af6..005076d0 100644 --- a/ember-scoped-css/src/app-css-unplugin.js +++ b/ember-scoped-css/src/app-css-unplugin.js @@ -1,10 +1,4 @@ import { createUnplugin } from 'unplugin'; -import replaceGlimmerAst from './replaceGlimmerAst.js'; -import path from 'path'; -import getPostfix from './getPostfix.js'; -import getClassesTagsFromCss from './getClassesTagsFromCss.js'; -import { readFile } from 'fs/promises'; -import fsExists from './fsExists.js'; export default createUnplugin(() => { return { diff --git a/ember-scoped-css/src/app-js-unplugin.js b/ember-scoped-css/src/app-js-unplugin.js index cc4d153d..10b23fd0 100644 --- a/ember-scoped-css/src/app-js-unplugin.js +++ b/ember-scoped-css/src/app-js-unplugin.js @@ -3,8 +3,6 @@ import replaceGlimmerAst from './replaceGlimmerAst.js'; import path from 'path'; import getPostfix from './getPostfix.js'; import getClassesTagsFromCss from './getClassesTagsFromCss.js'; -import { readFile } from 'fs/promises'; -import fsExists from './fsExists.js'; function* iterateOpcodes(opcodes) { for (let instruction of opcodes) { @@ -50,14 +48,11 @@ export default createUnplugin(({ appDir }) => { async transform(code, id) { const cssPath = id.replace(/(\.js)|(\.hbs)/, '.css'); - const cssFileName = path.basename(cssPath); const postfix = getPostfix(cssPath); return await replaceGlimmerAst(code, id, (opcodes, css) => { const { classes, tags } = getClassesTagsFromCss(css); - const a = code; // this.addWatchFile(cssPath); - const tmp = this; const insertions = []; for (let instruction of iterateOpcodes(opcodes[0])) { diff --git a/ember-scoped-css/src/babel-plugin-scoped-class.js b/ember-scoped-css/src/babel-plugin-scoped-class.js index 0cb161c4..fd92488a 100644 --- a/ember-scoped-css/src/babel-plugin-scoped-class.js +++ b/ember-scoped-css/src/babel-plugin-scoped-class.js @@ -5,9 +5,7 @@ const scopedClass = () => { visitor: { CallExpression(path, state) { if (path.node?.callee?.name === 'precompileTemplate') { - let source = ''; if (path.node.arguments[0].type === 'StringLiteral') { - source = path.node.arguments[0].value; path.node.arguments[0].value = replaceScopedClass( path.node.arguments[0].value, state.filename, diff --git a/ember-scoped-css/src/replaceScopedClass.js b/ember-scoped-css/src/replaceScopedClass.js index 410dd51b..e16cfbce 100644 --- a/ember-scoped-css/src/replaceScopedClass.js +++ b/ember-scoped-css/src/replaceScopedClass.js @@ -2,7 +2,7 @@ import recast from 'ember-template-recast'; import renameClass from './renameClass.js'; import getPostfix from './getPostfix.js'; -export default function (hbs, templatePath, basePath) { +export default function (hbs, templatePath) { let ast = recast.parse(hbs); let stack = []; const cssPath = templatePath.replace(/(\.hbs)?\.js$/, '.css'); @@ -13,7 +13,7 @@ export default function (hbs, templatePath, basePath) { enter(node) { stack.push(node); }, - exit(node) { + exit() { stack.pop(); }, }, diff --git a/ember-scoped-css/src/rollup-ember-template-imports-plugin.js b/ember-scoped-css/src/rollup-ember-template-imports-plugin.js index 477e2f9c..86c8633f 100644 --- a/ember-scoped-css/src/rollup-ember-template-imports-plugin.js +++ b/ember-scoped-css/src/rollup-ember-template-imports-plugin.js @@ -54,6 +54,7 @@ function resolutionFor(originalId) { } async function preprocessTemplates(id) { + // eslint-disable-next-line node/no-unsupported-features/es-syntax let ember = (await import('ember-source')).default; let contents = await fs.readFile(id, 'utf-8'); diff --git a/ember-scoped-css/test/getPostfix.js b/ember-scoped-css/test/getPostfix.js index 57a68aa2..229627b1 100644 --- a/ember-scoped-css/test/getPostfix.js +++ b/ember-scoped-css/test/getPostfix.js @@ -1,5 +1,4 @@ import { expect } from 'chai'; -import { stub } from 'sinon'; import getPostfix from '../src/getPostfix.js'; describe('getPostfix', function () { diff --git a/ember-scoped-css/test/rewriteCss.js b/ember-scoped-css/test/rewriteCss.js index 86e8585f..e309584a 100644 --- a/ember-scoped-css/test/rewriteCss.js +++ b/ember-scoped-css/test/rewriteCss.js @@ -1,5 +1,4 @@ import { expect } from 'chai'; -import { stub } from 'sinon'; import rewriteCss from '../src/rewriteCss.js'; describe('rewriteCss', function () { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ea9931c9..10d95bd3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -59,6 +59,9 @@ importers: esbuild: specifier: ^0.17.17 version: 0.17.17 + eslint: + specifier: ^8.38.0 + version: 8.38.0 mocha: specifier: ^10.2.0 version: 10.2.0 @@ -2072,6 +2075,21 @@ packages: requiresBuild: true optional: true + /@eslint-community/eslint-utils@4.4.0(eslint@8.38.0): + resolution: {integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + eslint: ^6.0.0 || ^7.0.0 || >=8.0.0 + dependencies: + eslint: 8.38.0 + eslint-visitor-keys: 3.4.0 + dev: true + + /@eslint-community/regexpp@4.5.0: + resolution: {integrity: sha512-vITaYzIcNmjn5tF5uxcZ/ft7/RXGrMUIS9HalWckEOF6ESiwXKoMzAQf2UW0aVd6rnOeExTJVd5hmWXucBKGXQ==} + engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} + dev: true + /@eslint/eslintrc@0.4.3: resolution: {integrity: sha512-J6KFFz5QCYUJq3pf0mjEcCJVERbzv71PUIDczuh9JkwGEzced6CO5ADLHB1rbf/+oPBtoPfMYNOpGDzCANlbXw==} engines: {node: ^10.12.0 || >=12.0.0} @@ -2089,6 +2107,28 @@ packages: - supports-color dev: true + /@eslint/eslintrc@2.0.2: + resolution: {integrity: sha512-3W4f5tDUra+pA+FzgugqL2pRimUTDJWKr7BINqOpkZrC0uYI0NIc0/JFgBROCU07HR6GieA5m3/rsPIhDmCXTQ==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dependencies: + ajv: 6.12.6 + debug: 4.3.4(supports-color@8.1.1) + espree: 9.5.1 + globals: 13.20.0 + ignore: 5.2.4 + import-fresh: 3.3.0 + js-yaml: 4.1.0 + minimatch: 3.1.2 + strip-json-comments: 3.1.1 + transitivePeerDependencies: + - supports-color + dev: true + + /@eslint/js@8.38.0: + resolution: {integrity: sha512-IoD2MfUnOV58ghIHCiil01PcohxjbYR/qCxsoC+xNgUwh1EY8jOOrYmu3d3a71+tJJ23uscEV4X2HJWMsPJu4g==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dev: true + /@glimmer/component@1.1.2(@babel/core@7.21.0): resolution: {integrity: sha512-XyAsEEa4kWOPy+gIdMjJ8XlzA3qrGH55ZDv6nA16ibalCR17k74BI0CztxuRds+Rm6CtbUVgheCVlcCULuqD7A==} engines: {node: 6.* || 8.* || >= 10.*} @@ -2204,6 +2244,17 @@ packages: /@handlebars/parser@2.0.0: resolution: {integrity: sha512-EP9uEDZv/L5Qh9IWuMUGJRfwhXJ4h1dqKTT4/3+tY0eu7sPis7xh23j61SYUnNF4vqCQvvUXpDo9Bh/+q1zASA==} + /@humanwhocodes/config-array@0.11.8: + resolution: {integrity: sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g==} + engines: {node: '>=10.10.0'} + dependencies: + '@humanwhocodes/object-schema': 1.2.1 + debug: 4.3.4(supports-color@8.1.1) + minimatch: 3.1.2 + transitivePeerDependencies: + - supports-color + dev: true + /@humanwhocodes/config-array@0.5.0: resolution: {integrity: sha512-FagtKFz74XrTl7y6HCzQpwDfXP0yhxe9lHLD1UZxjvZIcbyRz8zTFF/yYNfSfzU414eDwZ1SrO0Qvtyf+wFMQg==} engines: {node: '>=10.10.0'} @@ -2215,6 +2266,11 @@ packages: - supports-color dev: true + /@humanwhocodes/module-importer@1.0.1: + resolution: {integrity: sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==} + engines: {node: '>=12.22'} + dev: true + /@humanwhocodes/object-schema@1.2.1: resolution: {integrity: sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==} dev: true @@ -2714,6 +2770,14 @@ packages: acorn: 7.4.1 dev: true + /acorn-jsx@5.3.2(acorn@8.8.2): + resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} + peerDependencies: + acorn: ^6.0.0 || ^7.0.0 || ^8.0.0 + dependencies: + acorn: 8.8.2 + dev: true + /acorn-walk@7.2.0: resolution: {integrity: sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA==} engines: {node: '>=0.4.0'} @@ -6723,6 +6787,14 @@ packages: esrecurse: 4.3.0 estraverse: 4.3.0 + /eslint-scope@7.2.0: + resolution: {integrity: sha512-DYj5deGlHBfMt15J7rdtyKNq/Nqlv5KfU4iodrQ019XESsRnwXH9KAE0y3cwtUHDo2ob7CypAnCqefh6vioWRw==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dependencies: + esrecurse: 4.3.0 + estraverse: 5.3.0 + dev: true + /eslint-utils@2.1.0: resolution: {integrity: sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==} engines: {node: '>=6'} @@ -6750,6 +6822,11 @@ packages: engines: {node: '>=10'} dev: true + /eslint-visitor-keys@3.4.0: + resolution: {integrity: sha512-HPpKPUBQcAsZOsHAFwTtIKcYlCje62XB7SEAcxjtmW6TD1WVpkS6i6/hOVtTZIl4zGj/mBqpFVGvaDneik+VoQ==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dev: true + /eslint@7.32.0: resolution: {integrity: sha512-VHZ8gX+EDfz+97jGcgyGCyRia/dPOd6Xh9yPv8Bl1+SoaIwD+a/vlrOmGRUyOYu7MwUhc7CxqeaDZU13S4+EpA==} engines: {node: ^10.12.0 || >=12.0.0} @@ -6799,6 +6876,55 @@ packages: - supports-color dev: true + /eslint@8.38.0: + resolution: {integrity: sha512-pIdsD2jwlUGf/U38Jv97t8lq6HpaU/G9NKbYmpWpZGw3LdTNhZLbJePqxOXGB5+JEKfOPU/XLxYxFh03nr1KTg==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + hasBin: true + dependencies: + '@eslint-community/eslint-utils': 4.4.0(eslint@8.38.0) + '@eslint-community/regexpp': 4.5.0 + '@eslint/eslintrc': 2.0.2 + '@eslint/js': 8.38.0 + '@humanwhocodes/config-array': 0.11.8 + '@humanwhocodes/module-importer': 1.0.1 + '@nodelib/fs.walk': 1.2.8 + ajv: 6.12.6 + chalk: 4.1.2 + cross-spawn: 7.0.3 + debug: 4.3.4(supports-color@8.1.1) + doctrine: 3.0.0 + escape-string-regexp: 4.0.0 + eslint-scope: 7.2.0 + eslint-visitor-keys: 3.4.0 + espree: 9.5.1 + esquery: 1.4.2 + esutils: 2.0.3 + fast-deep-equal: 3.1.3 + file-entry-cache: 6.0.1 + find-up: 5.0.0 + glob-parent: 6.0.2 + globals: 13.20.0 + grapheme-splitter: 1.0.4 + ignore: 5.2.4 + import-fresh: 3.3.0 + imurmurhash: 0.1.4 + is-glob: 4.0.3 + is-path-inside: 3.0.3 + js-sdsl: 4.4.0 + js-yaml: 4.1.0 + json-stable-stringify-without-jsonify: 1.0.1 + levn: 0.4.1 + lodash.merge: 4.6.2 + minimatch: 3.1.2 + natural-compare: 1.4.0 + optionator: 0.9.1 + strip-ansi: 6.0.1 + strip-json-comments: 3.1.1 + text-table: 0.2.0 + transitivePeerDependencies: + - supports-color + dev: true + /esm@3.2.25: resolution: {integrity: sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==} engines: {node: '>=6'} @@ -6813,6 +6939,15 @@ packages: eslint-visitor-keys: 1.3.0 dev: true + /espree@9.5.1: + resolution: {integrity: sha512-5yxtHSZXRSW5pvv3hAlXM5+/Oswi1AUFqBmbibKb5s6bp3rGIDkyXU6xCoyuuLhijr4SFwPrXRoZjz0AZDN9tg==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dependencies: + acorn: 8.8.2 + acorn-jsx: 5.3.2(acorn@8.8.2) + eslint-visitor-keys: 3.4.0 + dev: true + /esprima@3.0.0: resolution: {integrity: sha512-xoBq/MIShSydNZOkjkoCEjqod963yHNXTLC40ypBhop6yPqflPz/vTinmCfSrGcywVLnSftRf6a0kJLdFdzemw==} engines: {node: '>=0.10.0'} @@ -7813,6 +7948,10 @@ packages: resolution: {integrity: sha512-8tLu60LgxF6XpdbK8OW3FA+IfTNBn1ZHGHKF4KQbEeSkajYw5PlYJcKluntgegDPTg8UkHjpet1T82vk6TQ68w==} dev: true + /grapheme-splitter@1.0.4: + resolution: {integrity: sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==} + dev: true + /growly@1.3.0: resolution: {integrity: sha512-+xGQY0YyAWCnqy7Cd++hc2JqMYzlm0dG30Jd0beaA64sROr8C4nt8Yc9V5Ro3avlSUDTN0ulqP/VBKi1/lLygw==} dev: true @@ -8601,6 +8740,10 @@ packages: merge-stream: 2.0.0 supports-color: 8.1.1 + /js-sdsl@4.4.0: + resolution: {integrity: sha512-FfVSdx6pJ41Oa+CF7RDaFmTnCaFhua+SNYQX74riGOpl96x+2jQCqEfQ2bnXu/5DPCqlRuiqyvTJM0Qjz26IVg==} + dev: true + /js-string-escape@1.0.1: resolution: {integrity: sha512-Smw4xcfIQ5LVjAOuJCvN/zIodzA/BBSsluuoSykP+lUvScIi4U6RJLfwHet5cxFnCswUjISV8oAXaqaJDY3chg==} engines: {node: '>= 0.8'}