Sfoglia il codice sorgente

The load() function should take path relative to the root.

Piotrek Koszuliński 10 anni fa
parent
commit
b89a86b255
4 ha cambiato i file con 48 aggiunte e 1 eliminazioni
  1. 13 1
      src/load__amd.js
  2. 2 0
      src/load__cjs.js
  3. 2 0
      src/load__esnext.js
  4. 31 0
      tests/ckeditor/load.js

+ 13 - 1
src/load__amd.js

@@ -9,8 +9,20 @@
 // Otherwise we would use the global one which resolves paths relatively to the base dir.
 // Otherwise we would use the global one which resolves paths relatively to the base dir.
 import require from 'require';
 import require from 'require';
 
 
-// NOTE: modulePath MUST BE RELATIVE to this module.
+/**
+ * Loads a module.
+ *
+ *		load( CKEDITOR.getModulePath( 'core/editor' ) )
+ *			.then( ( EditorModule ) => {
+ *				const Editor = EditorModule.default;
+ *			} );
+ *
+ * @param {String} modulePath Path to the module, relative to `ckeditor.js`'s parent directory (the root).
+ * @returns {Promise}
+ */
 export default function load( modulePath ) {
 export default function load( modulePath ) {
+	modulePath = '../' + modulePath;
+
 	return new Promise( ( resolve, reject ) => {
 	return new Promise( ( resolve, reject ) => {
 		require(
 		require(
 			[ modulePath ],
 			[ modulePath ],

+ 2 - 0
src/load__cjs.js

@@ -8,6 +8,8 @@
 /* global require */
 /* global require */
 
 
 export default function load( modulePath ) {
 export default function load( modulePath ) {
+	modulePath = '../' + modulePath;
+
 	return new Promise( ( resolve ) => {
 	return new Promise( ( resolve ) => {
 		resolve( require( modulePath ) );
 		resolve( require( modulePath ) );
 	} );
 	} );

+ 2 - 0
src/load__esnext.js

@@ -8,6 +8,8 @@
 /* global System */
 /* global System */
 
 
 export default function load( modulePath ) {
 export default function load( modulePath ) {
+	modulePath = '../' + modulePath;
+
 	return System
 	return System
 		.import( modulePath )
 		.import( modulePath )
 		.then( ( module ) => {
 		.then( ( module ) => {

+ 31 - 0
tests/ckeditor/load.js

@@ -0,0 +1,31 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+const modules = bender.amd.require( 'ckeditor', 'ckeditor5/load' );
+let CKEDITOR, load;
+
+before( () => {
+	CKEDITOR = modules.ckeditor;
+	load = modules[ 'ckeditor5/load' ];
+} );
+
+describe( 'load()', () => {
+	it( 'loads ckeditor.js', () => {
+		return load( 'ckeditor.js' )
+			.then( ( CKEDITORModule ) => {
+				expect( CKEDITORModule.default ).to.equal( CKEDITOR );
+			} );
+	} );
+
+	it( 'loads core/editor', () => {
+		return load( CKEDITOR.getModulePath( 'core/editor' ) )
+			.then( ( EditorModule ) => {
+				expect( EditorModule.default ).to.be.a( 'function' );
+			} );
+	} );
+} );
+