mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-23 13:56:44 +00:00
Utilize __non_webpack_require__ so we can source virtual files
This removes the need for a separate init module. Using `__non_webpack_require__` will force Webpack to compile as `require` instead of `__webpack_require__`, allowing ResourceLoader to inject the virtual file. Change-Id: I00203f4665b49cb92ee9db356445fdc2ab17fc5f
This commit is contained in:
parent
46b458cc0c
commit
15215cb81f
|
@ -162,15 +162,6 @@
|
|||
"codemirror-toggle-label"
|
||||
]
|
||||
},
|
||||
"ext.CodeMirror.v6.WikiEditor.init": {
|
||||
"packageFiles": [
|
||||
"ext.CodeMirror.v6.WikiEditor.init.js",
|
||||
{
|
||||
"name": "ext.CodeMirror.data.js",
|
||||
"callback": "MediaWiki\\Extension\\CodeMirror\\DataScript::makeScript"
|
||||
}
|
||||
]
|
||||
},
|
||||
"ext.CodeMirror.v6.WikiEditor": {
|
||||
"dependencies": [
|
||||
"web2017-polyfills",
|
||||
|
@ -180,7 +171,11 @@
|
|||
"ext.CodeMirror.v6.messages"
|
||||
],
|
||||
"packageFiles": [
|
||||
"dist/main.js"
|
||||
"dist/main.js",
|
||||
{
|
||||
"name": "ext.CodeMirror.data.js",
|
||||
"callback": "MediaWiki\\Extension\\CodeMirror\\DataScript::makeScript"
|
||||
}
|
||||
],
|
||||
"styles": [
|
||||
"ext.CodeMirror.v6.WikiEditor.less",
|
||||
|
|
|
@ -103,7 +103,7 @@ class Hooks implements
|
|||
}
|
||||
|
||||
if ( $this->shouldUseV6( $out ) ) {
|
||||
$out->addModules( 'ext.CodeMirror.v6.WikiEditor.init' );
|
||||
$out->addModules( 'ext.CodeMirror.v6.WikiEditor' );
|
||||
} else {
|
||||
$out->addModules( 'ext.CodeMirror.WikiEditor' );
|
||||
|
||||
|
|
2
resources/dist/main.js
vendored
2
resources/dist/main.js
vendored
File diff suppressed because one or more lines are too long
2
resources/dist/main.js.map.json
vendored
2
resources/dist/main.js.map.json
vendored
File diff suppressed because one or more lines are too long
|
@ -1,3 +0,0 @@
|
|||
require( './ext.CodeMirror.data.js' );
|
||||
|
||||
mw.loader.load( 'ext.CodeMirror.v6.WikiEditor' );
|
|
@ -13,6 +13,9 @@
|
|||
"browser": true,
|
||||
"commonjs": true
|
||||
},
|
||||
"globals": {
|
||||
"__non_webpack_require__": "readonly"
|
||||
},
|
||||
"rules": {
|
||||
"es-x/no-array-prototype-includes": 0,
|
||||
"es-x/no-class-fields": 0,
|
||||
|
|
|
@ -5,6 +5,11 @@ import { defaultKeymap, history, historyKeymap } from '@codemirror/commands';
|
|||
import { searchKeymap } from '@codemirror/search';
|
||||
import { bracketMatching } from '@codemirror/language';
|
||||
|
||||
// Necessary so that `require` doesn't get mangled into `__webpack_require__`,
|
||||
// which ResourceLoader won't recognize and thus be unable to load the virtual file.
|
||||
// See https://webpack-v3.jsx.app/api/module-variables/#__non_webpack_require__-webpack-specific-
|
||||
__non_webpack_require__( '../ext.CodeMirror.data.js' );
|
||||
|
||||
/**
|
||||
* @class CodeMirrorWikiEditor
|
||||
*/
|
||||
|
|
|
@ -13,5 +13,7 @@ mw.config.get = jest.fn().mockReturnValue( '1000+ edits' );
|
|||
mw.track = jest.fn();
|
||||
mw.Api.prototype.saveOption = jest.fn();
|
||||
|
||||
// eslint-disable-next-line no-underscore-dangle, camelcase
|
||||
global.__non_webpack_require__ = jest.fn();
|
||||
global.$ = require( 'jquery' );
|
||||
$.fn.textSelection = () => {};
|
||||
|
|
|
@ -63,7 +63,7 @@ class HookTest extends MediaWikiIntegrationTestCase {
|
|||
public function provideOnBeforePageDisplay(): array {
|
||||
return [
|
||||
[ false, 2, 'ext.CodeMirror.WikiEditor' ],
|
||||
[ true, 1, 'ext.CodeMirror.v6.WikiEditor.init' ]
|
||||
[ true, 1, 'ext.CodeMirror.v6.WikiEditor' ]
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue