Skip to content

Commit

Permalink
get bower dependencies from npm
Browse files Browse the repository at this point in the history
a couple of packages have different layouts (jquery-ui, react, xterm), but little is changed

a 'bower-lite' script copies dependencies from node_modules to `static/components` to match previous installation location
  • Loading branch information
minrk committed Oct 25, 2021
1 parent 41f1483 commit 3fe19a9
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 71 deletions.
3 changes: 0 additions & 3 deletions .bowerrc

This file was deleted.

3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ include CONTRIBUTING.rst
include README.md
include CHANGELOG.md
include package.json
include bower.json
include .bowerrc
include bower-lite
include pyproject.toml
include setup.py
include setupbase.py
Expand Down
38 changes: 38 additions & 0 deletions bower-lite
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
"""
bower-lite
Since Bower's on its way out,
stage frontend dependencies from node_modules into components
"""
import json
import os
import shutil
from os.path import join

HERE = os.path.abspath(os.path.dirname(__file__))


components = join(HERE, "notebook", "static", "components")
node_modules = join(HERE, "node_modules")

if os.path.exists(components):
shutil.rmtree(components)
os.mkdir(components)

with open(join(HERE, "package.json")) as f:
package_json = json.load(f)

renames = {
"jquery-ui-dist": "jquery-ui",
}

dependencies = package_json["dependencies"]
for dep in dependencies:
src = join(node_modules, dep)
dest_name = renames.get(dep, dep)
dest = join(components, dest_name)
print(f"{src} -> {dest}")
shutil.copytree(src, dest)
29 changes: 0 additions & 29 deletions bower.json

This file was deleted.

1 change: 0 additions & 1 deletion notebook/templates/notebook.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
window.mathjax_url = "{{mathjax_url}}";
</script>

<link rel="stylesheet" href="{{ static_url("components/bootstrap-tour/build/css/bootstrap-tour.min.css") }}" type="text/css" />
<link rel="stylesheet" href="{{ static_url("components/codemirror/lib/codemirror.css") }}">

{{super()}}
Expand Down
14 changes: 7 additions & 7 deletions notebook/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
<title>{% block title %}Jupyter Notebook{% endblock %}</title>
{% block favicon %}<link id="favicon" rel="shortcut icon" type="image/x-icon" href="{{static_url("base/images/favicon.ico") }}">{% endblock %}
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="stylesheet" href="{{static_url("components/jquery-ui/themes/smoothness/jquery-ui.min.css") }}" type="text/css" />
<link rel="stylesheet" href="{{static_url("components/jquery-ui-themes/themes/smoothness/jquery-ui.min.css") }}" type="text/css" />
<link rel="stylesheet" href="{{static_url("components/jquery-typeahead/dist/jquery.typeahead.min.css") }}" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">

{% block stylesheet %}
<link rel="stylesheet" href="{{ static_url("style/style.min.css") }}" type="text/css"/>
{% endblock %}
<link rel="stylesheet" href="{{ base_url }}custom/custom.css" type="text/css" />
<script src="{{static_url("components/es6-promise/promise.min.js")}}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url('components/react/react.production.min.js')}}" type="text/javascript"></script>
<script src="{{static_url('components/react/react-dom.production.min.js')}}" type="text/javascript"></script>
<script src="{{static_url('components/create-react-class/index.js')}}" type="text/javascript"></script>
<script src="{{static_url("components/es6-promise/dist/promise-1.0.0.min.js")}}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url('components/react/umd/react.production.min.js')}}" type="text/javascript"></script>
<script src="{{static_url('components/react-dom/umd/react-dom.production.min.js')}}" type="text/javascript"></script>
<script src="{{static_url('components/create-react-class/create-react-class.min.js')}}" type="text/javascript"></script>
<script src="{{static_url('components/requirejs/require.js') }}" type="text/javascript" charset="utf-8"></script>
<script>
require.config({
Expand All @@ -34,15 +34,15 @@
underscore : 'components/underscore/underscore-min',
backbone : 'components/backbone/backbone-min',
jed: 'components/jed/jed',
jquery: 'components/jquery/jquery.min',
jquery: 'components/jquery/dist/jquery.min',
json: 'components/requirejs-plugins/src/json',
text: 'components/requirejs-text/text',
bootstrap: 'components/bootstrap/dist/js/bootstrap.min',
bootstraptour: 'components/bootstrap-tour/build/js/bootstrap-tour.min',
'jquery-ui': 'components/jquery-ui/jquery-ui.min',
moment: 'components/moment/min/moment-with-locales',
codemirror: 'components/codemirror',
termjs: 'components/xterm.js/xterm',
termjs: 'components/xterm/dist/xterm',
typeahead: 'components/jquery-typeahead/dist/jquery.typeahead.min',
},
map: { // for backward compatibility
Expand Down
2 changes: 1 addition & 1 deletion notebook/templates/terminal.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{% block stylesheet %}
{{super()}}
<link rel="stylesheet" href="{{ static_url("terminal/css/override.css") }}" type="text/css" />
<link rel="stylesheet" href="{{static_url("components/xterm.js-css/index.css") }}" type="text/css" />
<link rel="stylesheet" href="{{static_url("components/xterm/dist/xterm.css") }}" type="text/css" />
{% endblock %}

{% block headercontainer %}
Expand Down
31 changes: 27 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,46 @@
"url": "https://github.com/jupyter/notebook.git"
},
"scripts": {
"bower": "bower install",
"bower": "python3 bower-lite",
"build": "python setup.py js css",
"build:webpack": "webpack --mode production",
"build:watch": "npm run watch",
"watch": "onchange 'notebook/static/**/!(*.min).js' 'notebook/static/**/*.less' 'bower.json' -- npm run build"
"watch": "onchange 'notebook/static/**/!(*.min).js' 'notebook/static/**/*.less' -- npm run build"
},
"dependencies": {
"backbone": "~1.2",
"bootstrap": "~3.4",
"bootstrap-tour": "^0.9.0",
"codemirror": "5.56.0",
"create-react-class": "^15.6.3",
"es6-promise": "~1.0",
"font-awesome": "~4.7.0",
"jed": "~1.1.1",
"jquery": "~3.5.0",
"jquery-typeahead": "~2.10.6",
"jquery-ui-dist": "^1.12.0",
"jquery-ui-themes": "^1.12.0",
"marked": "~0.7",
"mathjax": "^2.7.4",
"moment": "~2.19.3",
"react": "~16.0.0",
"react-dom": "~16.0.0",
"requirejs": "^2.3.6",
"requirejs-plugins": "~1.0.2",
"requirejs-text": "~2.0.15",
"text-encoding": "^0.7.0",
"underscore": "~1.8.3",
"xterm": "~3.1.0"
},
"devDependencies": {
"@babel/core": "^7.15.0",
"@babel/preset-env": "^7.15.0",
"@jupyterlab/apputils": "^3.1.3",
"babel-loader": "^8.2.2",
"babel-polyfill": "^6.26.0",
"bower": "^1.8.8",
"less": "~2",
"onchange": "^6.0.0",
"po2json": "^0.4.5",
"requirejs": "^2.3.6",
"webpack": "^5.46.0",
"webpack-cli": "^4.7.2"
}
Expand Down
39 changes: 19 additions & 20 deletions setupbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,32 +131,31 @@ def find_package_data():
static_data.extend([
pjoin(components, "backbone", "backbone-min.js"),
pjoin(components, "bootstrap", "dist", "js", "bootstrap.min.js"),
pjoin(components, "bootstrap-tour", "build", "css", "bootstrap-tour.min.css"),
pjoin(components, "bootstrap-tour", "build", "js", "bootstrap-tour.min.js"),
pjoin(components, "create-react-class", "index.js"),
pjoin(components, "bootstrap-tour", "lib", "bootstrap-tour.js"),
pjoin(components, "create-react-class", "create-react-class.js"),
pjoin(components, "font-awesome", "css", "*.css"),
pjoin(components, "es6-promise", "*.js"),
pjoin(components, "es6-promise", "dist", "*.min.js"),
pjoin(components, "font-awesome", "fonts", "*.*"),
pjoin(components, "jed", "jed.js"),
pjoin(components, "jquery", "jquery.min.js"),
pjoin(components, "jquery", "dist", "jquery.min.js"),
pjoin(components, "jquery-typeahead", "dist", "jquery.typeahead.min.js"),
pjoin(components, "jquery-typeahead", "dist", "jquery.typeahead.min.css"),
pjoin(components, "jquery-ui", "jquery-ui.min.js"),
pjoin(components, "jquery-ui", "themes", "smoothness", "jquery-ui.min.css"),
pjoin(components, "jquery-ui", "themes", "smoothness", "images", "*"),
pjoin(components, "jquery-ui-themes", "themes", "smoothness", "jquery-ui.min.css"),
pjoin(components, "jquery-ui-themes", "themes", "smoothness", "images", "*"),
pjoin(components, "marked", "lib", "marked.js"),
pjoin(components, "react", "react.production.min.js"),
pjoin(components, "react", "react-dom.production.min.js"),
pjoin(components, "react", "umd", "react.production.min.js"),
pjoin(components, "react-dom", "umd", "react-dom.production.min.js"),
pjoin(components, "requirejs", "require.js"),
pjoin(components, "requirejs-plugins", "src", "json.js"),
pjoin(components, "requirejs-text", "text.js"),
pjoin(components, "sanitizer", "index.js"),
pjoin(components, "underscore", "underscore-min.js"),
pjoin(components, "moment", "moment.js"),
pjoin(components, "moment", "min", "*.js"),
pjoin(components, "xterm.js", "index.js"),
pjoin(components, "xterm.js-css", "index.css"),
pjoin(components, "xterm.js-fit", "index.js"),
pjoin(components, "xterm", "dist", "xterm.js"),
pjoin(components, "xterm", "dist", "xterm.css"),
pjoin(components, "xterm", "dist", "addons", "fit", "fit.js"),
pjoin(components, "text-encoding", "lib", "encoding.js"),
])

Expand All @@ -167,7 +166,7 @@ def find_package_data():
static_data.append(pjoin(parent, f))

# Trim mathjax
mj = lambda *path: pjoin(components, 'MathJax', *path)
mj = lambda *path: pjoin(components, 'mathjax', *path)
static_data.extend([
mj('MathJax.js'),
mj('config', 'TeX-AMS-MML_HTMLorMML-full.js'),
Expand Down Expand Up @@ -360,10 +359,10 @@ def run(self):
])

class Bower(Command):
description = "fetch static client-side components with bower"
description = "fetch static client-side components"

user_options = [
('force', 'f', "force fetching of bower dependencies"),
('force', 'f', "force fetching of javascript components"),
]

def initialize_options(self):
Expand All @@ -384,7 +383,7 @@ def should_run(self):
if not os.path.exists(self.sanitizer_dir):
return True

bower_stale = mtime(self.bower_dir) < mtime(pjoin(repo_root, 'bower.json'))
bower_stale = mtime(self.bower_dir) < mtime(pjoin(repo_root, "package.json"))
if bower_stale:
return True

Expand All @@ -400,7 +399,7 @@ def should_run_npm(self):

def run(self):
if not self.should_run():
print("bower dependencies up to date")
print("static/components up to date")
return

if self.should_run_npm():
Expand All @@ -413,12 +412,12 @@ def run(self):

try:
run(
['bower', 'install', '--allow-root', '--config.interactive=false'],
[sys.executable, pjoin(repo_root, "bower-lite")],
cwd=repo_root,
env=env
env=env,
)
except OSError as e:
print("Failed to run bower: %s" % e, file=sys.stderr)
print("Failed to run bower-lite: %s" % e, file=sys.stderr)
print("You can install js dependencies with `npm install`", file=sys.stderr)
raise
# self.npm_components()
Expand Down
8 changes: 4 additions & 4 deletions tools/build-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ var rjs_config = {
underscore : 'components/underscore/underscore-min',
backbone : 'components/backbone/backbone-min',
jed: 'components/jed/jed',
jquery: 'components/jquery/jquery.min',
jquery: 'components/jquery/dist/jquery.min',
json: 'components/requirejs-plugins/src/json',
text: 'components/requirejs-text/text',
bootstrap: 'components/bootstrap/dist/js/bootstrap.min',
bootstraptour: 'components/bootstrap-tour/build/js/bootstrap-tour.min',
bootstraptour: 'components/bootstrap-tour/lib/bootstrap-tour',
"jquery-ui": 'components/jquery-ui/jquery-ui.min',
moment: 'components/moment/min/moment-with-locales',
codemirror: 'components/codemirror',
xterm: 'components/xterm.js/index',
"xtermjs-fit": 'components/xterm.js-fit/index',
xterm: 'components/xterm/dist/xterm',
"xtermjs-fit": 'components/xterm/dist/addons/fit/fit',
"jquery-typeahead": 'components/jquery-typeahead/dist/jquery.typeahead.min',
contents: 'empty:',
custom: 'empty:',
Expand Down

0 comments on commit 3fe19a9

Please sign in to comment.