Browse Source

wip fix handling of watch mode

Steven Silvester 4 years ago
parent
commit
501bdaa8c4

+ 10 - 5
builder/src/webpack.config.ext.ts

@@ -170,15 +170,20 @@ __webpack_public_path__ = ${webpackPublicPathString};
 class CleanupPlugin {
   apply(compiler: any) {
     compiler.hooks.done.tap('Cleanup', () => {
-      fs.unlinkSync(publicpath);
       // Find the remoteEntry file and add it to the package.json metadata
       const files = glob.sync(path.join(outputPath, 'remoteEntry.*.js'));
-      if (files.length !== 1) {
-        throw new Error('There is not a single remoteEntry file generated.');
-      }
+      let bestTime = -1;
+      let newestRemote = '';
+      files.forEach(fpath => {
+        const mtime = fs.statSync(fpath).mtime.getTime();
+        if (mtime > bestTime) {
+          newestRemote = fpath;
+          bestTime = mtime;
+        }
+      });
       const data = readJSONFile(path.join(outputPath, 'package.json'));
       const _build: any = {
-        load: path.basename(files[0])
+        load: path.basename(newestRemote)
       };
       if (exposes['./extension'] !== undefined) {
         _build.extension = './extension';

+ 19 - 14
jupyterlab/commands.py

@@ -353,7 +353,7 @@ def get_page_config(app_options=None):
         extensions.append(extension)
 
         # If there is disabledExtensions metadata, consume it.
-        if ext_data['jupyterlab']['disabledExtensions']:
+        if ext_data['jupyterlab'].get('disabledExtensions'):
             disabled_by_extensions_all[ext_data['name']] = ext_data['jupyterlab']['disabledExtensions']
 
     disabled_by_extensions = dict()
@@ -369,6 +369,23 @@ def get_page_config(app_options=None):
     return page_config
 
 
+def _get_dynamic_extensions():
+    dynamic_exts = dict()
+    dynamic_ext_dirs = dict()
+    for ext_dir in jupyter_path('labextensions'):
+        ext_pattern = ext_dir + '/**/package.json'
+        for ext_path in [path for path in glob(ext_pattern, recursive=True)]:
+            with open(ext_path) as fid:
+                data = json.load(fid)
+            if data['name'] not in dynamic_exts:
+                data['ext_dir'] = ext_dir
+                data['ext_path'] = os.path.dirname(ext_path)
+                data['is_local'] = False
+                dynamic_exts[data['name']] = data
+                dynamic_ext_dirs[ext_dir] = True
+    return dynamic_ext_dirs, dynamic_exts
+    
+
 class AppOptions(HasTraits):
     """Options object for build system"""
 
@@ -1174,19 +1191,7 @@ class _AppHandler(object):
 
         info['disabled_core'] = disabled_core
 
-        dynamic_exts = dict()
-        dynamic_ext_dirs = dict()
-        for ext_dir in jupyter_path('labextensions'):
-            ext_pattern = ext_dir + '/**/package.json'
-            for ext_path in [path for path in glob(ext_pattern, recursive=True)]:
-                with open(ext_path) as fid:
-                    data = json.load(fid)
-                if data['name'] not in dynamic_exts:
-                    data['ext_dir'] = ext_dir
-                    data['ext_path'] = os.path.dirname(ext_path)
-                    data['is_local'] = False
-                    dynamic_exts[data['name']] = data
-                    dynamic_ext_dirs[ext_dir] = True
+        dynamic_ext_dirs, dynamic_exts = _get_dynamic_extensions()
         info['dynamic_exts'] = dynamic_exts
         info['dynamic_ext_dirs'] = dynamic_ext_dirs
         return info

+ 19 - 3
jupyterlab/dynamic_labextensions.py

@@ -30,7 +30,7 @@ from jupyter_server.config_manager import BaseJSONConfigManager
 
 from traitlets.utils.importstring import import_item
 
-from .commands import build, AppOptions, _test_overlap
+from .commands import build, AppOptions, _test_overlap, _get_dynamic_extensions
 
 
 DEPRECATED_ARGUMENT = object()
@@ -182,7 +182,7 @@ def build_labextension(path, logger=None, development=False, static_url=None):
     subprocess.check_call(arguments, cwd=ext_path)
 
 
-def watch_labextension(path, logger=None, development=False):
+def watch_labextension(path, logger=None, development=True):
     """Watch a labextension in a given path"""
     core_path = osp.join(HERE, 'staging')
     ext_path = osp.abspath(path)
@@ -190,11 +190,27 @@ def watch_labextension(path, logger=None, development=False):
     if logger:
         logger.info('Building extension in %s' % path)
 
+    # Check to see if we need to create a symlink
+    dynamic_ext_dirs, dynamic_exts = _get_dynamic_extensions()
+
+    with open(pjoin(ext_path, 'package.json')) as fid:
+        ext_data = json.load(fid)
+    
+    os.makedirs(ext_data['jupyterlab']['outputDir'], exist_ok=True)
+
+    if ext_data['name'] not in dynamic_exts:
+        full_dest = develop_labextension(ext_path, sys_prefix=True)
+    else:
+        full_dest = pjoin(dynamic_exts[ext_data['name']]['ext_dir'], ext_data['name'])
+        if not osp.islink(full_dest):
+            shutil.rmtree(full_dest)
+            os.symlink(ext_path, full_dest)
+
+    builder = _ensure_builder(ext_path, core_path)
     arguments = ['node', builder, '--core-path', core_path,  '--watch', ext_path]
     if development:
         arguments.append('--development')
 
-    builder = _ensure_builder(ext_path, core_path)
     subprocess.check_call(arguments, cwd=ext_path)
 
 

+ 1 - 1
jupyterlab/labextensions.py

@@ -204,7 +204,7 @@ class BuildLabExtensionApp(BaseExtensionApp):
 class WatchLabExtensionApp(BaseExtensionApp):
     description = "Watch labextension"
 
-    development = Bool(False, config=True,
+    development = Bool(True, config=True,
         help="Build in development mode")
 
     def run_task(self):

+ 1 - 0
jupyterlab/upgrade_extension.py

@@ -90,6 +90,7 @@ def update_extension(target, interactive=True):
         data.setdefault('scripts', dict())
         for (key, value) in temp_data['scripts'].items():
             data['scripts'][key] = value
+        del data['scripts']['install-ext']
     else:
         warnings.append('package.json scripts must be updated manually')