@dword-design/base-config-web-extension 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -6,7 +6,7 @@ Copyright &copy; Sebastian Landwehr <info@sebastianlandwehr.com>
6
6
 
7
7
  and licensed under:
8
8
 
9
- [MIT License](https://opensource.org/licenses/MIT)
9
+ [MIT License](https://opensource.org/license/mit/)
10
10
 
11
11
  ## MIT License
12
12
 
package/README.md CHANGED
@@ -102,5 +102,5 @@ Thanks a lot for your support! ❤️
102
102
 
103
103
  ## License
104
104
 
105
- [MIT License](https://opensource.org/licenses/MIT) © [Sebastian Landwehr](https://sebastianlandwehr.com)
105
+ [MIT License](https://opensource.org/license/mit/) © [Sebastian Landwehr](https://sebastianlandwehr.com)
106
106
  <!-- /LICENSE -->
package/dist/config.js ADDED
@@ -0,0 +1,24 @@
1
+ import vue from '@vitejs/plugin-vue';
2
+ import P from 'path';
3
+ import { defineConfig } from 'vite';
4
+ import babel from 'vite-plugin-babel';
5
+ import eslint from 'vite-plugin-eslint';
6
+ import webExtension from 'vite-plugin-web-extension';
7
+ import getManifest from "./get-manifest.js";
8
+ process.env.TARGET = process.env.TARGET || 'chrome';
9
+ export default defineConfig({
10
+ build: {
11
+ outDir: P.join('dist', process.env.TARGET)
12
+ },
13
+ plugins: [vue(), webExtension({
14
+ browser: process.env.TARGET,
15
+ manifest: () => getManifest({
16
+ browser: process.env.TARGET
17
+ }),
18
+ scriptViteConfig: {
19
+ plugins: [eslint({
20
+ fix: true
21
+ }), babel()]
22
+ }
23
+ })]
24
+ });
package/dist/dev.js CHANGED
@@ -1,6 +1,7 @@
1
- import webpack from 'webpack';
2
- import getWebpackConfig from "./get-webpack-config.js";
3
- export default (config => (target = 'firefox-desktop') => {
4
- process.env.WEB_EXT_TARGET = target;
5
- return new Promise(() => webpack(getWebpackConfig(config)).watch({}, () => {}));
6
- });
1
+ import { execaCommand } from 'execa';
2
+ export default (() => browser => execaCommand('vite', {
3
+ env: {
4
+ TARGET: browser
5
+ },
6
+ stdio: 'inherit'
7
+ }));
@@ -0,0 +1,53 @@
1
+ import fs from 'fs-extra';
2
+ import loadPkg from 'load-pkg';
3
+ import { pick } from 'lodash-es';
4
+ export default (async ({
5
+ browser
6
+ }) => {
7
+ var _config$css, _config$css2;
8
+ const packageConfig = await loadPkg();
9
+ const config = await fs.readJson('config.json').catch(() => ({}));
10
+ const iconExists = await fs.exists('assets/icon.png');
11
+ const popupExists = await fs.exists('popup.html');
12
+ return {
13
+ name: config.name,
14
+ ...pick(packageConfig, ['version', 'description']),
15
+ manifest_version: 3,
16
+ ...(iconExists && {
17
+ icons: {
18
+ 128: 'assets/icon.png'
19
+ }
20
+ }),
21
+ ...(('action' in config || popupExists) && {
22
+ action: {
23
+ ...(iconExists && {
24
+ default_icon: 'assets/icon.png'
25
+ }),
26
+ ...(popupExists && {
27
+ default_popup: 'popup.html'
28
+ }),
29
+ ...(typeof config.action === 'object' && config.action)
30
+ }
31
+ }),
32
+ ...(((await fs.exists('content.js')) || ((_config$css = config.css) === null || _config$css === void 0 ? void 0 : _config$css.length) > 0) && {
33
+ content_scripts: [{
34
+ js: ['content.js'],
35
+ ...(((_config$css2 = config.css) === null || _config$css2 === void 0 ? void 0 : _config$css2.length) > 0 && {
36
+ css: config.css
37
+ }),
38
+ matches: config.matches || ['<all_urls>']
39
+ }]
40
+ }),
41
+ ...((await fs.exists('background.js')) && {
42
+ background: {
43
+ ...(browser === 'firefox' ? {
44
+ persistent: false,
45
+ scripts: ['background.js']
46
+ } : {
47
+ service_worker: 'background.js'
48
+ })
49
+ }
50
+ }),
51
+ ...pick(config, ['permissions', 'browser_specific_settings', 'css'])
52
+ };
53
+ });
package/dist/index.js CHANGED
@@ -1,20 +1,27 @@
1
1
  import depcheckParserSass from '@dword-design/depcheck-parser-sass';
2
2
  import endent from "@dword-design/functions/dist/endent.js";
3
3
  import packageName from 'depcheck-package-name';
4
- import { execaCommand } from 'execa';
5
- import fs from 'fs-extra';
4
+ import { createRequire } from 'module';
5
+ import outputFiles from 'output-files';
6
+ import P from 'path';
7
+ import { fileURLToPath } from 'url';
6
8
  import dev from "./dev.js";
7
9
  import lint from "./lint.js";
8
10
  import prepublishOnly from "./prepublish-only.js";
11
+ const __dirname = P.dirname(fileURLToPath(import.meta.url));
12
+ const isInNodeModules = __dirname.split(P.sep).includes('node_modules');
13
+ const resolver = createRequire(import.meta.url);
9
14
  export default (config => ({
10
- allowedMatches: ['artifacts', 'assets', 'background.js', 'content.js', 'config.json', 'icon.png', 'index.spec.js', 'options.html', 'popup.html', 'options.js', 'popup.js', 'model'],
15
+ allowedMatches: ['assets', 'background.js', 'content.js', 'config.json', 'icon.png', 'index.spec.js', 'options.html', 'popup.html', 'options.js', 'popup.js', 'model'],
11
16
  commands: {
12
17
  dev: {
13
- arguments: '[target]',
18
+ arguments: '[browser]',
14
19
  handler: dev(config)
15
20
  },
16
- prepublishOnly: prepublishOnly(config),
17
- source: () => execaCommand('git archive --output=source.zip HEAD')
21
+ prepublishOnly: {
22
+ arguments: '[browser]',
23
+ handler: prepublishOnly(config)
24
+ }
18
25
  },
19
26
  depcheckConfig: {
20
27
  parsers: {
@@ -31,26 +38,29 @@ export default (config => ({
31
38
  GOOGLE_REFRESH_TOKEN: '${{ secrets.GOOGLE_REFRESH_TOKEN }}'
32
39
  },
33
40
  deployPlugins: [[packageName`@semantic-release/exec`, {
34
- prepareCmd: 'yarn prepublishOnly'
35
- }], [packageName`semantic-release-chrome`, {
36
- asset: 'extension.zip',
37
- extensionId: config.chromeExtensionId,
38
- target: 'draft'
41
+ prepareCmd: `yarn prepublishOnly && yarn prepublishOnly firefox && zip -r dist/chrome dist/chrome.zip && zip -r dist/firefox dist/firefox.zip && git archive --output=dist/firefox-sources.zip HEAD && ${packageName`publish-browser-extension`} --chrome-zip=dist/chrome.zip --firefox-zip=dist/firefox.zip --firefox-sources=dist/firefox-sources.zip`
39
42
  }]],
40
43
  editorIgnore: ['.eslintrc.json', 'dist'],
41
- gitignore: ['/.eslintrc.json', '/artifacts', '/dist', 'source.zip'],
44
+ gitignore: ['/.eslintrc.json', '/dist'],
42
45
  isLockFileFixCommitType: true,
43
46
  lint,
44
- prepare: () => fs.outputFile('.eslintrc.json', JSON.stringify({
45
- extends: packageName`@dword-design/eslint-config`,
46
- globals: {
47
- browser: 'readonly'
48
- }
49
- }, undefined, 2)),
47
+ prepare: () => {
48
+ const configPath = isInNodeModules ? '@dword-design/base-config-web-extension/config' : `./${P.relative(process.cwd(), resolver.resolve('./config.js')).split(P.sep).join('/')}`;
49
+ outputFiles({
50
+ '.eslintrc.json': `${JSON.stringify({
51
+ extends: packageName`@dword-design/eslint-config`
52
+ }, undefined, 2)}\n`,
53
+ 'vite.config.js': endent`
54
+ import config from '${configPath}'
55
+
56
+ export default config
57
+ `
58
+ });
59
+ },
50
60
  readmeInstallString: endent`
51
61
  ## Recommended setup
52
- * Node.js 12.16.0
53
- * Yarn 1.21.1
62
+ * Node.js 20.11.1
63
+ * Yarn 1.22.19
54
64
 
55
65
  ## Install
56
66
  \`\`\`bash
@@ -59,18 +69,13 @@ export default (config => ({
59
69
 
60
70
  ## Running a development server
61
71
  \`\`\`bash
62
- $ yarn dev [target]
72
+ $ yarn dev [browser]
63
73
  \`\`\`
64
- Available targets are \`firefox\` and \`chrome\`. Default is \`firefox\`.
74
+ Available browsers are \`firefox\` and \`chrome\`. Default is \`firefox\`.
65
75
 
66
76
  ## Building the extension for upload
67
77
  \`\`\`bash
68
- $ yarn prepublishOnly
69
- \`\`\`
70
-
71
- ## Archiving the source for upload
72
- \`\`\`bash
73
- $ yarn source
78
+ $ yarn prepublishOnly [browser]
74
79
  \`\`\`
75
80
  `
76
81
  }));
package/dist/lint.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { execaCommand } from 'execa';
2
2
  export default (async () => {
3
3
  try {
4
- await execaCommand('eslint --fix --ext .js,.json --ignore-path .gitignore .', {
4
+ await execaCommand('eslint --fix --ext .js,.json,.vue --ignore-path .gitignore .', {
5
5
  all: true
6
6
  });
7
7
  } catch (error) {
@@ -1,11 +1,7 @@
1
- import webpack from 'webpack';
2
- import getWebpackConfig from "./get-webpack-config.js";
3
- export default (config => () => new Promise((resolve, reject) => webpack(getWebpackConfig(config), (error, stats) => {
4
- if (error) {
5
- return reject(error);
6
- }
7
- if (stats.hasErrors()) {
8
- return reject(new Error(JSON.stringify(stats.toJson().errors, undefined, 2)));
9
- }
10
- return resolve();
11
- })));
1
+ import { execaCommand } from 'execa';
2
+ export default (() => browser => execaCommand('vite build', {
3
+ env: {
4
+ TARGET: browser
5
+ },
6
+ stdio: 'inherit'
7
+ }));
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@dword-design/base-config-web-extension",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "repository": "dword-design/base-config-web-extension",
5
5
  "funding": "https://github.com/sponsors/dword-design",
6
6
  "license": "MIT",
7
7
  "author": "Sebastian Landwehr <info@sebastianlandwehr.com>",
8
8
  "type": "module",
9
- "exports": "./dist/index.js",
9
+ "exports": {
10
+ ".": "./dist/index.js",
11
+ "./config": "./dist/config.js"
12
+ },
10
13
  "main": "dist/index.js",
11
14
  "files": [
12
15
  "dist"
@@ -27,22 +30,19 @@
27
30
  "@dword-design/eslint-config": "^5.0.1",
28
31
  "@dword-design/functions": "^5.0.27",
29
32
  "@semantic-release/exec": "^6.0.3",
30
- "babel-loader": "^9.1.3",
31
- "better-node-env": "^1.0.3",
32
- "copy-webpack-plugin": "^12.0.2",
33
+ "@vitejs/plugin-vue": "^5.0.4",
33
34
  "depcheck-package-name": "^3.0.1",
34
- "eslint-webpack-plugin": "^4.0.1",
35
35
  "execa": "^8.0.1",
36
36
  "fs-extra": "^11.1.0",
37
37
  "load-pkg": "^4.0.0",
38
- "node-sass": "^9.0.0",
39
- "raw-loader": "^4.0.1",
40
- "sass-loader": "^14.0.0",
41
- "semantic-release-chrome": "dword-design/semantic-release-chrome#fork",
42
- "webext-webpack-plugin": "^0.0.11",
43
- "webextension-polyfill": "^0.10.0",
44
- "webpack": "^5.33.2",
45
- "webpackbar": "^6.0.0"
38
+ "lodash-es": "^4.17.21",
39
+ "output-files": "^2.0.0",
40
+ "publish-browser-extension": "^2.1.3",
41
+ "vite": "^5.1.4",
42
+ "vite-plugin-babel": "^1.2.0",
43
+ "vite-plugin-eslint": "^1.8.1",
44
+ "vite-plugin-web-extension": "^4.1.1",
45
+ "vue": "^3.4.21"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@dword-design/base": "^11.0.2",
@@ -51,7 +51,7 @@
51
51
  "@dword-design/tester-plugin-tmp-dir": "^2.0.3",
52
52
  "express": "^4.17.1",
53
53
  "globby": "^14.0.0",
54
- "output-files": "^2.0.0",
54
+ "webextension-polyfill": "^0.10.0",
55
55
  "with-local-tmp-dir": "^5.0.1",
56
56
  "xvfb": "^0.4.0"
57
57
  },
@@ -1,44 +0,0 @@
1
- import pick from "@dword-design/functions/dist/pick.js";
2
- import fs from 'fs-extra';
3
- import loadPkg from 'load-pkg';
4
- export default (async configString => {
5
- var _packageConfig, _config;
6
- const packageConfig = await loadPkg();
7
- const config = JSON.parse(configString);
8
- const iconExists = fs.existsSync('assets/icon.png');
9
- const popupExists = fs.existsSync('popup.html');
10
- return JSON.stringify({
11
- name: config.name,
12
- ...(_packageConfig = packageConfig, pick(['version', 'description'])(_packageConfig)),
13
- manifest_version: 2,
14
- ...(iconExists && {
15
- icons: {
16
- 128: 'assets/icon.png'
17
- }
18
- }),
19
- ...(('browser_action' in config || popupExists) && {
20
- browser_action: {
21
- ...(iconExists && {
22
- default_icon: 'assets/icon.png'
23
- }),
24
- ...(popupExists && {
25
- default_popup: 'popup.html'
26
- }),
27
- ...(typeof config.browser_action === 'object' && config.browser_action)
28
- }
29
- }),
30
- ...(fs.existsSync('content.js') && {
31
- content_scripts: [{
32
- js: ['browser-polyfill.js', 'content.js'],
33
- matches: config.matches || ['<all_urls>']
34
- }]
35
- }),
36
- ...(fs.existsSync('background.js') && {
37
- background: {
38
- persistent: false,
39
- scripts: ['browser-polyfill.js', 'background.js']
40
- }
41
- }),
42
- ...(_config = config, pick(['permissions', 'browser_specific_settings'])(_config))
43
- });
44
- });
@@ -1,70 +0,0 @@
1
- import nodeEnv from 'better-node-env';
2
- import CopyWebpackPlugin from 'copy-webpack-plugin';
3
- import packageName from 'depcheck-package-name';
4
- import EslintWebpackPlugin from 'eslint-webpack-plugin';
5
- import fs from 'fs-extra';
6
- import { WebExtWebpackPlugin } from 'webext-webpack-plugin';
7
- import WebpackBar from 'webpackbar';
8
- import configToManifest from "./config-to-manifest.js";
9
- export default (config => ({
10
- devtool: false,
11
- entry: {
12
- ...(fs.existsSync('background.js') && {
13
- background: './background.js'
14
- }),
15
- ...(fs.existsSync('content.js') && {
16
- content: './content.js'
17
- }),
18
- ...(fs.existsSync('options.js') && {
19
- options: './options.js'
20
- }),
21
- ...(fs.existsSync('popup.js') && {
22
- popup: './popup.js'
23
- })
24
- },
25
- mode: nodeEnv === 'production' ? nodeEnv : 'development',
26
- module: {
27
- rules: [{
28
- test: /\.js$/,
29
- use: {
30
- loader: packageName`babel-loader`
31
- }
32
- }, {
33
- test: /\.s[ac]ss$/i,
34
- use: [packageName`raw-loader`, packageName`sass-loader`]
35
- }]
36
- },
37
- output: {
38
- clean: true
39
- },
40
- plugins: [new EslintWebpackPlugin({
41
- failOnWarning: true,
42
- fix: true
43
- }), new WebpackBar(), new CopyWebpackPlugin({
44
- patterns: [{
45
- from: 'config.json',
46
- to: 'manifest.json',
47
- transform: configToManifest
48
- }, {
49
- from: require.resolve('webextension-polyfill')
50
- }, {
51
- from: 'assets',
52
- noErrorOnMissing: true,
53
- to: 'assets'
54
- }, {
55
- from: 'options.html',
56
- noErrorOnMissing: true
57
- }, {
58
- from: 'popup.html',
59
- noErrorOnMissing: true
60
- }]
61
- }), new WebExtWebpackPlugin({
62
- build: {
63
- artifactsDir: 'artifacts'
64
- },
65
- run: {
66
- startUrl: config.startUrl,
67
- target: process.env.WEB_EXT_TARGET
68
- }
69
- })]
70
- }));