{"id":15023984,"url":"https://github.com/sap/ui5-simple-require","last_synced_at":"2026-03-16T20:01:13.020Z","repository":{"id":44007612,"uuid":"232818850","full_name":"SAP/ui5-simple-require","owner":"SAP","description":"Import UI5 modules into NodeJS applications, allowing isolation of UI5 components and injection of  dependencies to create an isolated test environment.","archived":false,"fork":false,"pushed_at":"2025-08-21T14:21:18.000Z","size":688,"stargazers_count":9,"open_issues_count":12,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-10-19T15:56:04.858Z","etag":null,"topics":["open-source","sapui5","ui5","ui5-tooling"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SAP.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-09T13:44:37.000Z","updated_at":"2025-04-21T23:43:24.000Z","dependencies_parsed_at":"2024-06-19T11:26:20.480Z","dependency_job_id":"51961278-adce-46e4-ae22-e7b2b323831e","html_url":"https://github.com/SAP/ui5-simple-require","commit_stats":{"total_commits":100,"total_committers":9,"mean_commits":11.11111111111111,"dds":0.6,"last_synced_commit":"4b972f73100ebbda9f9f472e60dce00f98ea2928"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/SAP/ui5-simple-require","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP%2Fui5-simple-require","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP%2Fui5-simple-require/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP%2Fui5-simple-require/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP%2Fui5-simple-require/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SAP","download_url":"https://codeload.github.com/SAP/ui5-simple-require/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP%2Fui5-simple-require/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279873374,"owners_count":26237968,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-19T02:00:07.647Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["open-source","sapui5","ui5","ui5-tooling"],"created_at":"2024-09-24T19:59:40.735Z","updated_at":"2025-10-19T18:31:10.037Z","avatar_url":"https://github.com/SAP.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![REUSE status](https://api.reuse.software/badge/github.com/SAP/ui5-simple-require)](https://api.reuse.software/info/github.com/SAP/ui5-simple-require)\n\n\n# ui5-simple-require\n\n## Description\n\nImport UI5 modules into NodeJS applications, allowing isolation of UI5 components and injection of dependencies to create an isolated test environment.\n\n## Requirements\n* [NodeJS](https://nodejs.org/en/download/), version 8.0 or higher\n\n## Installation\nInstall at your Node.js project:\n```\n$ npm install ui5-simple-require --save-dev\n```\n\n## Usage\n\nWhen importing UI5 modules, there are few things to consider, the two major things that need to be resolved are *SAP's Global Context* and *Dependency Lookup*. This tool provides ways to inject both dependencies based on their path as well as properties that will be injected in global context when the module is loaded. \n\n### Require UI5 Modules \n\n`ui5require` will load modules that are in `sap.ui.define` style. For example, suppose you have the following UI5 module:\n\n```js\nsap.ui.define([], function() {\n  const myClass = function() { /* CODE */ };\n    /* CODE */\n  return myClass;\n});\n```\n\nWhen running the import code: \n\n```javascript\nconst ui5require = require('ui5-simple-require').ui5require;\nconst MyClass = ui5require('./myUI5Class.js');\n\nvar myObject = new MyClass();\n```\n\nThe constant variable `MyClass` will contain the constructor function. \n\n### Resolving Dependencies\n\nSuppose a similar module now with defined dependencies.\n\n```js\nsap.ui.define(['/path/to/Dependency'], function() {\n  const myClass = function(Dependency) { /* CODE */ };\n    /* CODE */\n  return myClass;\n});\n```\n\nDependencies will be resolved in the following order:\n\n- Position injected\n- Path injected\n- Loaded\n\n#### Position Injected\n\n```js\nconst MyClass = ui5require('./myUI5Class.js', [ new FakeDependency() ]);\n```\n\n#### Path Injected\n\nInjecting by path will create a virtual path lookup. Where, whenever a dependency is required, it will first look at this injected path. \n\n```js\nconst moduleLoader = require('ui5-simple-require');\nconst ui5require = moduleLoader.ui5require;\n\nmoduleLoader.inject('/path/to/dependency', new FakeDependency);\nconst MyClass = ui5require('./myUI5Class.js');\n```\n\n#### Loaded \n\nWhen no injection methods are passed, module loader will try to load the module by its path. Meaning that if a file that matches `/path/to/Dependency` is found in the path, the original dependency is loaded. \n\n### Injecting Global Dependency\n\nInjecting a global dependency works similar to injecting dependencies. A global lookup is created for whenever a new module is loaded a global context is injected. \n\n```js\nconst moduleLoader = require('ui5-simple-require');\nconst ui5require = moduleLoader.ui5require;\n\nmoduleLoader.globalContext({ sap: { someValue: \"custom value\" }});\nconst MyClass = ui5require('./myUI5Class.js');\n```\n\nThe injected object will be under global context. Such as:\n\n```js\n// ... ui5 module\nsap.someValue; // evaluates to \"custom value\"\n```\n\n### Loading UI5 Libraries\n\nYou can use the `importLib` function to load UI5-style libraries. ui5-simple-require populates the namespace of the library in the global context with an empty object. If you need a more elaborate implementation, you can inject using the `globalContext` function.\n\n```js\n// ./test/example/mockLib/com/sap/mockLib/library.js\nsap.ui.define([], function() {\n  com.sap.mockLib.namespace; // does not throw error, global context is populated with mock object\n  sap.ui.getCore().initLibrary({\n    name: \"com.sap.mockLib.namespace\",\n    version: \"2.0\",\n    dependencies: [\"sap.ui.core\"],\n    types: [],\n    interfaces: [],\n    controls: [],\n    elements: []\n  });\n  return \"loaded\";\n\n************************************************************\n\n// ./test/apiTest.js\nconst ui5Library = API.importLib(\n  \"./example/mockLib\",\n  \"com/sap/mockLib\",\n  \"com.sap.mockLib.namespace\"\n); // ui5Library evaluates to \"loaded\"\n\n```\n\n## Example\n\nUsing mocha and chai for writting unit tests.\n\n```js\n// MoneyChanger.js\nsap.ui.define([\"./coin\", \"./note\", \"./CurrencyServer\"], function(Coin, Note, CurrencyServer) {\n\tvar MoneyChanger = function() {};\n\n\tMoneyChanger.prototype.getChange = function(i) {\n             ... \n\t}\n\n\treturn MoneyChanger;\n});\n\n************************************************************\n// MoneyChangerTest.js\nconst expect = require('chai').expect;\n\nconst API = require('ui5-simple-require');\nconst ui5require = require('ui5-simple-require').ui5require;\n\nAPI.inject('/src/main/webapp/money/CurrencyServer', FakeCurrencyServer);\n\nconst MoneyChanger = ui5require('./src/main/webapp/money/changer');\nconst Note = ui5require('./src/main/webapp/money/note');\nconst Coin = ui5require('./src/main/webapp/money/coin');\n\ndescribe(\"Should test money changer\", () =\u003e {\n\n  let changer;\n\n  beforeEach(() =\u003e {\n    changer = new MoneyChanger();\n  })\n\n  it(\"Should create money changer class\", () =\u003e {\n    expect(changer).to.be.an(\"object\");\n  });\n\t\n  it(\"Should get one coin from value 1\", () =\u003e {\n    expect(changer.getChange(1)).to.be.deep.equal([ new Coin(1) ]);\n  });\n\n  it(\"Should get one note from value 2\", () =\u003e {\n    expect(changer.getChange(2)).to.be.deep.equal([ new Note(2) ]);  \n  });\n\n  it(\"Should get one note and one coin from value 3\", () =\u003e {\n    expect(changer.getChange(3)).to.be.deep.equal([ new Note(2), new Coin(1) ]);\n  });\n\n  // ...\n\n});\n\n```\n\n## API\n\n#### `ui5require(path [, position_dependencies] [, global_context])`\n\n- `path` \\\u003cstring\\\u003e\n- `position_dependencies` \\\u003cArray\\\u003e\n- `global_context` \\\u003cObject\\\u003e\n- **Returns:** \\\u003cObject\\\u003e Loaded Module.\n\n\n#### `inject(path, dependency)`\n\n- `path` \\\u003cstring\\\u003e\n- `dependency` \\\u003cObject\\\u003e \n\n\n#### `clearInjection()`\n\nDeletes any dependencies passed with `inject`\n\n\n#### `globalContext(context)`\n\n- `context` \\\u003cstring\\\u003e\n\n\n#### `clearGlobalContext()`\n\nDeletes any global object passed with `globalContext(...)`\n\n#### `importLib(libRootPath, libFilePath, libUI5Namespace)`\n\nImport UI5 libraries\n\n- `libRootPath` \\\u003cstring\\\u003e\n- `libFilePath` \\\u003cstring\\\u003e \n- `libUI5Namespace` \\\u003cstring\\\u003e \n- **Returns:** \\\u003cObject\\\u003e Loaded UI5 library module. \n\n\n#### `createExtendableFromPrototype(prototype)`\n\n- `prototype` \\\u003cObject\\\u003e\n- **Returns:** \\\u003cObject\\\u003e prototype with UI5's fake `extend` method. \n\n\n#### `createExtendableFromObj(prototype)`\n\n- `prototype` \\\u003cstring\\\u003e\n- **Returns:** \\\u003cObject\\\u003e class with UI5's fake `extend` method. \n\n\n#### `[DEPRECATED] import(path [, position_dependencies] [, global_context])`\n\n- `path` \\\u003cstring\\\u003e\n- `position_dependencies` \\\u003cArray\\\u003e\n- `global_context` \\\u003cObject\\\u003e\n- **Returns: ** \\\u003cObject\\\u003e Loaded Module.\n\n## How to obtain support\n\nIf you think you found a bug or need help using the module, please create a new [github issue](https://github.com/SAP/ui5-simple-require/issues/new). \n\nThis project is provided \"as-is\", with no expected changes or support.\n\n\n## License\nCopyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved.\nThis file is licensed under the Apache Software License, v. 2 except as noted otherwise in the [LICENSE](LICENSE.txt) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsap%2Fui5-simple-require","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsap%2Fui5-simple-require","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsap%2Fui5-simple-require/lists"}