Loading library.js from bad path - sapui5

I have updated OpenUI5 of my project from 1.42.7 to 1.60.12 (LTS)
If I try to run the app with the new version, I have this error:
Uncaught Error: failed to load 'sap/ui/core/library.js' from resources/sap/ui/core/library.js: 404 - Not Found**
The tree structure of my project has OpenUI5 files into resources/openui path:
In index.html, I set src in this mode:
<script id="sap-ui-bootstrap"
src="resources/openui/sap-ui-core.js"
data-sap-ui-theme="sap_belize"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-libs="sap.m"
data-sap-ui-preload=""
data-sap-ui-resourceroots='{
"ui5bp": "./",
"model": "./model"
}'
></script>
It seems that the first call of sap-ui-core.js finishes correctly (from Webcontent/resources/openui) but then the call of library.js is called from Webcontent/resources/, not from Webcontent/resources/openui.
In 1.42 version, all works fine.
Note: if I try to retrieve OpenUI5 resources from CDN, all works fine...
src="https://openui5.hana.ondemand.com/1.60.12/resources/sap-ui-core.js"

Option 1 (recommended)
Move the UI5 resources to the resources folder directly underneath.
˅ 📂resources
˃ 📁openui
˅ 📂sap
˃ 📁base
˃ 📁f
˃ 📁m
...
...
sap-ui-core.js
According to the topic Bootstrapping: Loading and Initializing - Initialization Process, UI5 will try to fetch library resources from the following path by default:
Library bootstrap file /<context-path>/resources/<library-name>/library(-preload).js
Having a deviating path (/resources/openui/<library-name>/ in between) makes fetching the library files incompatible with default settings.
Option 2 (without changing the folder structure)
Define a new default base URL in index.html as early as possible. E.g. via the global configuration object:
<script>
window["sap-ui-config"] = {
resourceRoots: {
"": "./resources/openui/", // <-- new base URL
"ui5bp": "./",
// ...
},
libs: "sap.ui.core, sap.m",
async: true,
theme: "sap_belize",
compatVersion: "edge",
// ...
};
</script>
<script id="sap-ui-bootstrap" src="resources/openui/sap-ui-core.js"></script>
This one works too as resolving "" will always work as a fallback
Note that the empty prefix ("") will always match and thus serves as a fallback for any search. source

Related

Local module import tree possibility?

In my local package, there is a tree of modules, like this:
# source/main.py
from source import worker
def run():
return worker.func()
# source/worker.py
def func():
return 'hello'
I want to demonstrate this package with PyScript (before my package needs to be installed), but do not want to rewrite the whole package for the sake of PyScript. This "index.htm" calls the main.run(). It is OK until the main wants to import the worker module so that it can call its func().
<head>
..
<py-env>
paths:
- source/main.py
- source/worker.py
</py-env>
</head>
<body>
<py-script>
import main
main.run()
</py-script>
</body>
The "import worker" would work, but as I stated above, it is "from source import worker" and cannot be changed just to make it work in PyScript.
Could I define somehow that the root for the local module imports is above "source", and imports like "import source.module.py" should work?
It is not possible to do
from source import worker
because source is not a module, it is a folder. Pyscript is not same as python. The whole context is different. There is no need for it also. You can have it all together working and reachable if you declare nodes py-env and py-script like below.
index.html in application root folder:
<html>
<head>
<link rel="stylesheet" pyscript.css" />
<script defer src="pyscript.js"></script>
<!--<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js" onerror=scriptLoadFailure('pyscr ipt.js')></script> -->
<py-env>
paths:
./source/worker.py
./source/main.py
</py-env>
</head>
<body>
<py-script src="./source/worker.py"></py-script>
<py-script src="./source/main.py"></py-script>
</body>
</html>
The modules in py-env are declared with exactly 4 spaces indentation (no tab char) and starting from application root folder ( ./ ) folowed by subfolder and module. In body section both modules are declared as src attribute of py-script nodes. This way they are like unioned and operational without import one or other nor from one import something. You can just call the function from wherever you need to.
The modules are both in the source subfolder (though I prefer puting main in the app root along with index.html). There is just one change in main.py where I put the call of run() function for it was excluded from html.
Modules in ./source/ subfolder are
#
# source/main.py
def run():
return func()
run()
#
#
# source/worker.py
def func():
return 'hello'
Open it in browser and you'll see hello (tested with Chrome & Edge) meaning that run() command from main.py has called func() function from worker.py without importing anything.
And if you realy need to keep those imports all I can suggest is to do a replace of those imports to end up like below. It can be done with any editor and it will work both with python and pyscript.
try:
from source import worker
except:
pass
Regards...
Since the current PyScript does not do such, I created a patched version and proposed the PyScript project to pull it into a future version. See the ticket with my comment and the attached zip containing the solution:
Add Local Package Loading to Py-Env #519

How to get Codeigniter 3 to use project root instead of referencing full file path on localhost for key folders

I've looked around and I'm sure this is common but can't seem to get the right answer.
I've just recently set up a Codeigniter 3 project on my localhost and a migrating some Codeigniter 2 code.
The index.php file is a bit different.
I can get the project up and running except the main folders references in the index.php file such as APPLICATION and others I've added like "ASSETS" etc are loading like this:
<link href="http://[::1]/projectOne/E:\public_html\projectOne\assets\css\style.php?1537317115" rel="stylesheet" type="text/css" >
Even when I set a base_url:
<link href="http://localhost/projectOne/E:\public_html\projectOne\assets\css\style.php?1537317115" rel="stylesheet" type="text/css" >
I've checked it wasn't just the folders I added by echoing out the APPPATH variable:
define('APPPATH', $application_folder.DIRECTORY_SEPARATOR);
echo APPPATH;
Which produces:
E:\public_html\projectOne\application\
What am I missing here?
How do I get my paths to folder set in the index.php to just use the project root, and not the whole filepath on the computer?
Figured it out. For anyone else that hits this issue.
This new part in CI3:
if (($_temp = realpath($application_folder)) !== FALSE)
{
$application_folder = $_temp;
}
Allows you to more securely/easily have your application folder outside of the website root.
My additional ASSETS folder was then showing the full web path which you obviously don't want.
So commenting out this part leaving only:
$application_folder = strtr(
rtrim($application_folder, '/\\'),
'/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
);
And then setting you base_url value in the config.php file gives your CSS, JS and IMAGES proper site relative paths.

systemjs: mapping everything else to node_modules

I am having trouble getting systemjs to work so it resolves node modules.
I have the following in my index.html:
<script src="./system.config.js"></script>
<script>
System.import('blast/test')
.then(null, console.error.bind(console));
</script>
This is my configuration:
System.config({
baseUrl: '/',
packages: {
'app': {
defaultExtension: 'js',
}
},
packageConfigPaths: ['./node_modules/*/package.json'],
paths: {
'blast/*': 'app/*'
}
});
This works fine so far. However, I want to be able to also resolve node modules like lodash. So I set paths to this:
paths: {
'blast/*': 'app/*'
'*': './node_modules/*'
}
Now I can import lodash fine, but when importing blast/test I get the error /app/test 404 (not found). It seems, the package configuration isn't used anymore, this .js isn't appended. Anyone got any hints how to resolve this? I am using SystemJs 0.19.25 Standard.
Thanks, Robin
Try using map configuration here rather for your local package -
System.config({
map: {
blast: './app'
}
});
The ./ is necessary to distinguish the URL space from becoming the node_modules/app path (probably the reason you used paths here to begin with?)
It's also advisable to use baseURL: 'node_modules' instead of a wildcard paths entry (and they pretty much amount to the same thing).

jspm not loading bundles with --inject

Been experimenting with jspm and systemjs over the weekend. Everything is working fine except for the bundling jspm offers. I can load individual files, but jsmp refuses to load the bundle file (which is optimized).
I'm creating the bundle file using:
jspm bundle lib/login assets/js/1-login.js --inject
This updates the config.js file which looks like:
System.config({
baseURL: "/",
defaultJSExtensions: true,
transpiler: "babel",
babelOptions: {
"optional": [
"optimisation.modules.system"
]
},
paths: {
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*"
},
bundles: {
"1-login.js": [
"lib/login.js",
"lib/sample.js"
]
},
map: {....}
});
lib/login.js
import * as sample from 'lib/sample'
export function test() {
sample.testMethod();
}
lib/sample.js
import $ from 'jquery'
export function testMethod( ) {
console.log( $('body') );
}
So, according to the jsmp docs:
As soon as one of these modules is requested, the request is intercepted and the bundle is loaded dynamically first, before continuing with the module load.
It's my understanding that running
System.import('lib/login.js');
should load the bundle (and optimised file), but is doesn't - it just loads the actual file. What am I missing here? And as a bonus question, why is jquery not in the bundle list?
Well, figured out where I went wrong.
I keep all the generated assets in assets/js, but in my config.json I didn't change the baseUrl to reflect this. I did in fact have the baseUrl set correctly in package.json, which is why jspm didn't throw a lot of errors.
This was the same reason jquery wasn't loading, so problem solved :)

ReferenceError: JST is not defined in Sails.js

I have an ejs javascript template in:
/assets/linker/template
I changed the line in gruntfile.js from:
linker/**/*.html to linker/**/*.ejs
I have underscore.js in:
assets/linker/js
But when I try:
JST['assets/linker/templates/addUser.ejs']( obj ) from app.js
I get this error in the console:
ReferenceError: JST is not defined
Any help would be appreciated! Thanks!
I had the same problem. I solved it by manually linking JST into my index.ejs file.
so I just added
<script type="text/javascript" src="/jst.js"></script>
where I load my javascripts in sailsProject>views>home>index.ejs.
Not pretty, as the linker should do the job, but for now it works.
cheers
The Pipeline
The template files that are injected are specified in tasks/pipeline.js
The default is set to:
var templateFilesToInject = ['templates/**/*.html']
Files in assets/templates (or any subdirectory) with the .html file extension are injected.
Also check out the JST task in tasks/config/jst.js. It takes the template files to inject (from pipeline.js) and precompiles them into a file called jst.js.
Only once these other tasks have completed does the sails-linker begin its task. tasks/config/sails-linker.js takes the jst.js that was generated by the JST task and includes it into the template start and template end tag in .tmp/public/index.html, views/**/*.html, and views/**/*.ejs.
So the default pipeline for client-side templates is:
Precompile templates/**/*.html into jst.js
Include jst.js in index.html, views/**/*.html, and views/**/*.ejs between <!--TEMPLATES--> and <!--TEMPLATES END-->
Customization Examples
All of this default configuration can be changed to suit your needs. For example, to have templates with a different extension or multiple extensions edit the templateFilesToInject in tasks/pipeline.js:
let templateFilesToInject = [
'vendor/templates/vendor_template.html',
'templates/**/*.ejs',
'templates/**/*.html'
]
Or to only inject templates on specific views if they have the comment <!--TPL--><!--END TPL-->, edit the devTpl config in tasks/config/sails-linker.js:
// Bring in JST template object
devTpl: {
options: {
startTag: '<!--TPL-->',
endTag: '<!--END TPL-->',
fileTmpl: '<script type="text/javascript" src="%s"></script>',
appRoot: '.tmp/public'
},
files: {
'views/that/use/templates/**/*.ejs': [
'.tmp/public/jst.js'
]
}
}