Skip to content

Commit

Permalink
Merge branch 'main' into support-path
Browse files Browse the repository at this point in the history
  • Loading branch information
asimpson authored Nov 9, 2023
2 parents 6dacbed + 84d3a04 commit 3c5fe42
Show file tree
Hide file tree
Showing 63 changed files with 4,885 additions and 2,321 deletions.
4 changes: 2 additions & 2 deletions .config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ A common issue found with the current jest config involves importing an npm pack

```javascript
process.env.TZ = 'UTC';
const { grafanaESModules, nodeModulesToTransform } = require('./jest/utils');
const { grafanaESModules, nodeModulesToTransform } = require('./config/jest/utils');

module.exports = {
// Jest configuration provided by Grafana
Expand Down Expand Up @@ -161,4 +161,4 @@ services:
In this example we are assigning the environment variable `GRAFANA_IMAGE` to the build arg `grafana_image` with a default value of `grafana`. This will give you the possibility to set the value while running the docker-compose commands which might be convinent in some scenarios.

---
---
2 changes: 1 addition & 1 deletion .config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
'^.+\\.(t|j)sx?$': [
'@swc/jest',
{
sourceMaps: true,
sourceMaps: 'inline',
jsc: {
parser: {
syntax: 'typescript',
Expand Down
9 changes: 6 additions & 3 deletions .config/jest/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@
* This utility function is useful in combination with jest `transformIgnorePatterns` config
* to transform specific packages (e.g.ES modules) in a projects node_modules folder.
*/
const nodeModulesToTransform = (moduleNames) => `node_modules\/(?!(${moduleNames.join('|')})\/)`;
const nodeModulesToTransform = (moduleNames) => `node_modules\/(?!.*(${moduleNames.join('|')})\/.*)`;

// Array of known nested grafana package dependencies that only bundle an ESM version
const grafanaESModules = [
'.pnpm', // Support using pnpm symlinked packages
'@grafana/schema',
'd3',
'd3-color',
'd3-force',
'd3-interpolate',
'd3-scale-chromatic',
'ol',
'react-colorful',
'rxjs',
'uuid',
];

module.exports = {
nodeModulesToTransform,
grafanaESModules
}
grafanaESModules,
};
61 changes: 39 additions & 22 deletions .config/webpack/utils.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,59 @@
import fs from 'fs'
import path from 'path'
import util from 'util'
import glob from 'glob'
import { SOURCE_DIR } from './constants'

const globAsync = util.promisify(glob)
import fs from 'fs';
import process from 'process';
import os from 'os';
import path from 'path';
import util from 'util';
import { glob } from 'glob';
import { SOURCE_DIR } from './constants';


export function isWSL() {
if (process.platform !== 'linux') {
return false;
}

if (os.release().toLowerCase().includes('microsoft')) {
return true;
}

try {
return fs.readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft');
} catch {
return false;
}
}

export function getPackageJson() {
return require(path.resolve(process.cwd(), 'package.json'))
return require(path.resolve(process.cwd(), 'package.json'));
}

export function getPluginJson() {
return require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`))
return require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`));
}

export function hasReadme() {
return fs.existsSync(path.resolve(process.cwd(), SOURCE_DIR, 'README.md'))
return fs.existsSync(path.resolve(process.cwd(), SOURCE_DIR, 'README.md'));
}

// Support bundling nested plugins by finding all plugin.json files in src directory
// then checking for a sibling module.[jt]sx? file.
export async function getEntries(): Promise<Record<string, string>> {
const pluginsJson = await globAsync('**/src/**/plugin.json', { absolute: true })
const pluginsJson = await glob('**/src/**/plugin.json', { absolute: true });

const plugins = await Promise.all(pluginsJson.map((pluginJson) => {
const folder = path.dirname(pluginJson)
return globAsync(`${folder}/module.{ts,tsx,js,jsx}`, { absolute: true })
const folder = path.dirname(pluginJson);
return glob(`${folder}/module.{ts,tsx,js,jsx}`, { absolute: true });
})
)
);

return plugins.reduce((result, modules) => {
return modules.reduce((result, module) => {
const pluginPath = path.dirname(module)
const pluginName = path.relative(process.cwd(), pluginPath).replace(/src\/?/i, '')
const entryName = pluginName === '' ? 'module' : `${pluginName}/module`

result[entryName] = module
return result
}, result)
}, {})
const pluginPath = path.dirname(module);
const pluginName = path.relative(process.cwd(), pluginPath).replace(/src\/?/i, '');
const entryName = pluginName === '' ? 'module' : `${pluginName}/module`;

result[entryName] = module;
return result;
}, result);
}, {});
}
Loading

0 comments on commit 3c5fe42

Please sign in to comment.