Title: Enable NPM as package manager for NativeScript projects · Issue #362 · NativeScript/nativescript-cli · GitHub
Open Graph Title: Enable NPM as package manager for NativeScript projects · Issue #362 · NativeScript/nativescript-cli
X Title: Enable NPM as package manager for NativeScript projects · Issue #362 · NativeScript/nativescript-cli
Description: A common use case for NativeScript developers is the ability to install pure JavaScript modules from NPM. Currently this process is cumbersome and it is not straightforward how to require modules that have dependencies due to the nesting...
Open Graph Description: A common use case for NativeScript developers is the ability to install pure JavaScript modules from NPM. Currently this process is cumbersome and it is not straightforward how to require modules t...
X Description: A common use case for NativeScript developers is the ability to install pure JavaScript modules from NPM. Currently this process is cumbersome and it is not straightforward how to require modules t...
Opengraph URL: https://github.com/NativeScript/nativescript-cli/issues/362
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Enable NPM as package manager for NativeScript projects","articleBody":"A common use case for NativeScript developers is the ability to install pure JavaScript modules from NPM. Currently this process is cumbersome and it is not straightforward how to `require` modules that have dependencies due to the nesting of `node_modules` folders. The end goal is that `npm install ...` should work out of the box.\n### Relying on 'standards'\n\nIn order to support this a couple of things have to be changed in the CLI. Currently we create a project file `.tnsproject` that stores the app id (bundle identifier) along with the currently used version of each runtime. We plan to replace this file with `package.json` that will be compatible with [NPM package json](https://docs.npmjs.com/files/package.json) format. Here is the structure of a simple app following this rule:\n\n```\nmy-app/\n|-- app/\n|-- |-- App_Resources/\n|-- |-- tns_modules/\n|-- |-- ...\n|-- platforms/\n|-- node_modules/\n`-- package.json\n```\n### Preparing for a better world\n\nAssuming we have `package.json` in the root of the project will allow us to support `npm install lodash --save` which will install `lodash` into `node_modules` folder and save it as dependency in the `package.json`. All good but how `lodash` will end-up in the `tns_modules` folder of the app? This is where the second significant change will come into place. We will extend the `prepare` command to recursively transform the `node_modules` folder contents into `tns_modules` in the native platform project. This transformation should exclude all modules defined in the `devDependencies` section of the `package.json`.\n### Open questions:\n#### What should be the way to add NativeScript specific properties to the `project.json`?\n- prefixed with `tns_` or `nativescript_` Example:\n\n``` json\n{\n \"name\": \"myapp\",\n \"version\": \"10.3.1\",\n \"tns_id\": \"org.nativescript.myapp\",\n \"tns_platforms\": {\n \"ios\" : \"0.9.2\",\n \"android\" : \"0.9.0\"\n }\n}\n```\n- in a designated `nativescript` key. Example:\n\n``` json\n{\n \"name\": \"myapp\",\n \"version\": \"10.3.1\",\n \"nativescript\": {\n \"id\" : \"org.nativescript.myapp\",\n \"platforms\": {\n \"ios\" : \"0.9.2\",\n \"android\" : \"0.9.0\"\n }\n }\n}\n```\n#### Should we require NativeScript tailored modules published to NPM to have `nativescript` as an `engine`?\n\nExample:\n\n``` json\n{ \"engines\" : { \"nativescript\" : \">=0.9 \u003c0.10\" } }\n```\n\nor\n\n``` json\n{ \n \"engines\" : { \n \"nativescript-android\" : \"0.9.0\",\n \"nativescript-ios\" : \"0.9.3\" \n } \n}\n```\n\nThis will give us a couple of advantages:\n- We can warn (or error) the user if the module is not compatible with currently used runtime versions. \n- (Future) We can implement a Node compatibility layer in the runtimes that will be able to load Node dependent modules from `node_modules` folder by providing shims for all Node APIs.\n\n---\n### Tasks\n- [x] Remove `.tnsproject` and introduce `package.json`\n- [x] Move project properties into `nativescript` key in the `package.json`\n- [x] Extend `prepare` to copy the modules from `node_modules` into platform native project 'tns_modules'\n - [x] Flatten nested dependencies\n - [x] Do not `prepare` `devDependencies`.\n - [x] Make sure we do not degrade the performance during `prepare` when copying the modules. We can consider things like symlinks or broccoli.js kind of infrastructure. \n- [x] Guard the new code with tests\n- [x] Implement an upgrade procedure for the old projects\n","author":{"url":"https://github.com/ligaz","@type":"Person","name":"ligaz"},"datePublished":"2015-03-21T15:36:49Z","url":"https://github.com/NativeScript/nativescript-cli/issues/362"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:371b4927-e2e7-c88c-f57d-280ab3c76b51 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 81E0:2E5652:1AA58BE:21E9813:6B014FF1 |
| html-safe-nonce | e2ced5959f7d8eb3cacf50938e4f1d9429fc185baab7e7bd9a46a0ab5ea337c8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MUUwOjJFNTY1MjoxQUE1OEJFOjIxRTk4MTM6NkIwMTRGRjEiLCJ2aXNpdG9yX2lkIjoiMjQ1MTUxNDUyNzcyOTE0Mzc5MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 421f6a911d3b8c3b9fc6297eb2ea7ad436dfaaaa01fe7ff2aecabd4fda133192 |
| hovercard-subject-tag | issue:63419140 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NativeScript/nativescript-cli/362/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2cbcc5bcd06c2e591a4d1aa1dfdfdc23935d2cbf4da3504f903c76d37e488535/NativeScript/nativescript-cli/issues/362 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2cbcc5bcd06c2e591a4d1aa1dfdfdc23935d2cbf4da3504f903c76d37e488535/NativeScript/nativescript-cli/issues/362 |
| og:image:alt | A common use case for NativeScript developers is the ability to install pure JavaScript modules from NPM. Currently this process is cumbersome and it is not straightforward how to require modules t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ligaz |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/NativeScript/nativescript-cli git https://github.com/NativeScript/nativescript-cli.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 21347346 |
| octolytics-dimension-repository_nwo | NativeScript/nativescript-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 21347346 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/nativescript-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width