Skip to content

Commit f522735

Browse files
committed
It works
1 parent e3562c7 commit f522735

22 files changed

+399
-1387
lines changed
+4-48
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,6 @@
11
'use strict';
22

3-
module.exports = {
4-
root: true,
5-
parser: '@babel/eslint-parser',
6-
parserOptions: {
7-
ecmaVersion: 'latest',
8-
sourceType: 'module',
9-
babelOptions: {
10-
root: __dirname,
11-
},
12-
},
13-
plugins: ['ember', 'import'],
14-
extends: [
15-
'eslint:recommended',
16-
'plugin:ember/recommended',
17-
'plugin:prettier/recommended',
18-
],
19-
env: {
20-
browser: true,
21-
},
22-
rules: {},
23-
overrides: [
24-
// require relative imports use full extensions
25-
{
26-
files: ['src/**/*.{js,gjs}'],
27-
rules: {
28-
'import/extensions': ['error', 'always', { ignorePackages: true }],
29-
},
30-
},
31-
// node files
32-
{
33-
files: [
34-
'./.eslintrc.cjs',
35-
'./.prettierrc.cjs',
36-
'./.template-lintrc.cjs',
37-
'./addon-main.cjs',
38-
],
39-
parserOptions: {
40-
sourceType: 'script',
41-
},
42-
env: {
43-
browser: false,
44-
node: true,
45-
},
46-
plugins: ['n'],
47-
extends: ['plugin:n/recommended'],
48-
},
49-
],
50-
};
3+
const { configs } = require('@nullvoxpopuli/eslint-configs');
4+
5+
// accommodates: JS, TS, App, Addon, and V2 Addon
6+
module.exports = configs.ember();

ember-classic-import-meta-glob/.template-lintrc.cjs

-5
This file was deleted.

ember-classic-import-meta-glob/addon-main.cjs

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { assert } from '@ember/debug';
2+
import pico from 'picomatch';
3+
4+
/**
5+
* Only supported usage:
6+
* import.meta.glob('./*.svelte', { eager: true} )
7+
*
8+
* @param {string} glob
9+
* @param {{ eager: true }} glob
10+
* @param {string} modulePath file path prefixed with the module name, not CWD
11+
*/
12+
export function importMetaGlob(glob, options, modulePath) {
13+
assert(
14+
`the second argument to import.meta.glob must be passed and set to { eager: true }`,
15+
options && options.eager === true,
16+
);
17+
assert(
18+
`the third argument to import.meta.glob must be passed and be the module path. This is filled in automatically via the babel plugin. If you're seeing this something has gone wrong with installing the babel plugin`,
19+
modulePath,
20+
);
21+
22+
// WARNING: If you're reading this, know that requirejs is not public API.
23+
// Using it WILL make your upgrades harder in the future.
24+
// If you use this in your own code you aren't allowed to complain about upgrade
25+
// problems 😛
26+
let allModules = Object.keys(requirejs.entries);
27+
/**
28+
* 1. determine the directory the file is in.
29+
* 2. prepend that directory to the glob(s) (because requirejs uses full module paths)
30+
* 3. filter
31+
* 4. chop off the directory from the results to match the same relativeness
32+
*
33+
*/
34+
let [_last, ...reversedParts] = modulePath.split('/').reverse();
35+
let currentDir = reversedParts.reverse().join('/');
36+
37+
let fullGlobs = Array.isArray(glob)
38+
? glob.map((g) => `${modulePath}${g}`)
39+
: [`${modulePath}${glob}`];
40+
let isMatch = pico(fullGlobs);
41+
let matches = allModules.filter(isMatch);
42+
43+
let result = {};
44+
45+
for (let match of matches) {
46+
result[match] = requirejs(match);
47+
}
48+
49+
return result;
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const { ImportUtil } = require('babel-import-util');
2+
const {
3+
callExpression,
4+
memberExpression,
5+
identifier,
6+
stringLiteral,
7+
} = require('@babel/types');
8+
9+
// DEBUG:
10+
// https://astexplorer.net/#/gist/a72d97261099f82aac7be47112f66158/7e984bd728c0a4e9af4911b065f776aa21d68a7d
11+
module.exports = function (babel) {
12+
return {
13+
name: 'transform-import-meta-glob-for-ember-classic',
14+
visitor: {
15+
Program: {
16+
enter(path, state) {
17+
state.importUtil = new ImportUtil(babel, path);
18+
},
19+
},
20+
CallExpression(path, state) {
21+
if (path.node.callee?.object?.type !== 'MetaProperty') return;
22+
if (path.node.callee.property.name !== 'glob') return;
23+
24+
let args = path.node.arguments;
25+
26+
let { cwd, filename, importUtil } = state;
27+
let relative = filename.replace(new RegExp(`^${cwd}/`), '');
28+
29+
importUtil.replaceWith(path, (i) =>
30+
callExpression(
31+
i.import('ember-classic-import-meta-glob', 'importMetaGlob'),
32+
[...args, stringLiteral(relative)],
33+
),
34+
);
35+
},
36+
},
37+
};
38+
};

ember-classic-import-meta-glob/babel.config.json

-10
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const { hasPlugin, addPlugin } = require('ember-cli-babel-plugin-helpers');
5+
const pluginPath = path.join(__dirname, './babel-plugin.cjs');
6+
const Plugin = require.resolve(pluginPath);
7+
8+
module.exports = {
9+
name: require('./package').name,
10+
11+
included() {
12+
this._super.included.apply(this, arguments);
13+
14+
let parent = this.app || this.parent;
15+
16+
if (!hasPlugin(parent, pluginPath)) {
17+
addPlugin(parent, pluginPath);
18+
}
19+
},
20+
};

ember-classic-import-meta-glob/package.json

+19-29
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,30 @@
88
"repository": "",
99
"license": "MIT",
1010
"author": "",
11-
"exports": {
12-
".": "./dist/index.js",
13-
"./*": "./dist/*.js",
14-
"./addon-main.js": "./addon-main.cjs"
15-
},
1611
"files": [
17-
"addon-main.cjs",
18-
"declarations",
19-
"dist"
12+
"addon",
13+
"babel-plugin.cjs",
14+
"ember-addon-main.cjs"
2015
],
2116
"scripts": {
22-
"build": "rollup --config",
2317
"lint": "concurrently 'pnpm:lint:*(!fix)' --names 'lint:'",
2418
"lint:fix": "concurrently 'pnpm:lint:*:fix' --names 'fix:'",
25-
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
26-
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
2719
"lint:js": "eslint . --cache",
28-
"lint:js:fix": "eslint . --fix",
29-
"prepack": "rollup --config",
30-
"start": "rollup --config --watch",
31-
"test": "echo 'A v2 addon does not have tests, run tests in test-app'"
32-
},
33-
"dependencies": {
34-
"@embroider/addon-shim": "^1.8.7",
35-
"decorator-transforms": "^1.0.1"
20+
"lint:js:fix": "eslint . --fix"
3621
},
3722
"devDependencies": {
3823
"@babel/core": "^7.23.6",
3924
"@babel/eslint-parser": "^7.23.3",
40-
"@babel/runtime": "^7.17.0",
41-
"@embroider/addon-dev": "^4.1.0",
42-
"@rollup/plugin-babel": "^6.0.4",
43-
"babel-plugin-ember-template-compilation": "^2.2.1",
25+
"@nullvoxpopuli/eslint-configs": "^4.0.0",
4426
"concurrently": "^8.2.2",
45-
"ember-template-lint": "^5.13.0",
4627
"eslint": "^8.56.0",
4728
"eslint-config-prettier": "^9.1.0",
4829
"eslint-plugin-ember": "^11.12.0",
4930
"eslint-plugin-import": "^2.29.1",
5031
"eslint-plugin-n": "^16.4.0",
5132
"eslint-plugin-prettier": "^5.0.1",
5233
"prettier": "^3.1.1",
53-
"prettier-plugin-ember-template-tag": "^1.1.0",
54-
"rollup": "^4.9.1",
55-
"rollup-plugin-copy": "^3.5.0"
34+
"prettier-plugin-ember-template-tag": "^1.1.0"
5635
},
5736
"publishConfig": {
5837
"registry": "https://registry.npmjs.org"
@@ -61,8 +40,19 @@
6140
"edition": "octane"
6241
},
6342
"ember-addon": {
64-
"version": 2,
43+
"version": 1,
6544
"type": "addon",
66-
"main": "addon-main.cjs"
45+
"main": "ember-addon-main.cjs",
46+
"before": [
47+
"ember-cli-babel"
48+
]
49+
},
50+
"dependencies": {
51+
"@babel/types": "^7.24.6",
52+
"babel-import-util": "^3.0.0",
53+
"ember-auto-import": "^2.7.2",
54+
"ember-cli-babel": "^8.2.0",
55+
"ember-cli-babel-plugin-helpers": "^1.1.1",
56+
"picomatch": "^4.0.2"
6757
}
6858
}

ember-classic-import-meta-glob/rollup.config.mjs

-72
This file was deleted.

0 commit comments

Comments
 (0)