How do I use a local SPM package without a git repository? - swift-package-manager

Regarding Swift Package Manager, how do I use a local library package as a dependency of an executable package without a git repository? SwiftPM claims it allows you to pass in a local path in the url field, but then complains that it can't clone the repository.
from Package.swift
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "../../../string-calculator/swift/StringCalculator", from: "1.0.0"),
],
When running swift package update I get the following output:
Fetching /Users/tsd037/Documents/Workspace/Misc/tdd-kata/string-calculator/swift/StringCalculator
error: failed to clone; fatal: repository '/Users/tsd037/Documents/Workspace/Misc/tdd-kata/string-calculator/swift/StringCalculator' does not exist

Had the same problem, found the following solution in the API documentation.
https://developer.apple.com/documentation/swift_packages/package/3583304-init
https://developer.apple.com/documentation/swift_packages/package/dependency/3582846-package
Use the "path" parameter instead of "url"
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(path: "../../../string-calculator/swift/StringCalculator"),
],

Note that even for a local directory you have to create a git repository (local). Just run git init in the local directory, git commit and add a tag, e.g. git tag 1.0.0.

Related

Unable to publish an atom plugin

I am facing few issues. So whenever I am trying to publish a atom plugin using apm publish I am facing this error
Package must be in a Git repository before publishing: https://help.github.com/articles/create-a-repo
https://user-images.githubusercontent.com/90365542/154661659-c3866f5c-e4df-46bc-9b91-e0e444bad172.png
Apparently the package is in a github repository which is public as well https://github.com/avneesh0612/react-nextjs-snippets/tree/main/packages/atom
The package must reside in the root directory of a GitHub repository.
In your case the package is in https://github.com/avneesh0612/react-nextjs-snippets/tree/main/packages/atom but it must be directly in https://github.com/avneesh0612/react-nextjs-snippets/.
That is, there must be a package.json and a .git directory in that folder.

How to install unofficial Firebase extension

Looking for information on steps to install the unofficial firestore-nlp-extension, link below.
https://github.com/FirebaseExtended/firestore-nlp-extension
I read the firestore docs but did not see instructions to install a "custom" extension.
Any help is appreciated!
You need to install the extension from a local source but this was available during the alpha and the below link is no longer working
https://firebase.google.com/docs/extensions/alpha/install-extensions_community#install
The specific extension does not seem to be available on the Firebase system:
Error: The extension reference
'firebase/firestore-natural-language-processing#latest' doesn't exist.
This could happen for two reasons: -The publisher ID 'firebase'
doesn't exist or could be misspelled -The name of the extension
version 'firestore-natural-language-processing#latest' doesn't exist
or could be misspelled
For the current beta from the cli tool I found the following:
First, clone the git repo of the extension:
git clone git#github.com:FirebaseExtended/firestore-nlp-extension.git
then run the following commands to build the project:
cd firestore-nlp-extension/functions
yarn add -D rimraf
yarn build
cd ../..
and then to install this extension, run:
firebase ext:install ./firestore-nlp-extension --project=YOUR_PROJECT
if you get a path error you might need to find the right path such as:
firebase ext:install ./firestore-nlp-extension/functions --project=YOUR_PROJECT

How to install NPM package from GitHub for Meteor?

I have forked an npm package on GitHub, made changes to it, and now want to install the package in my Meteor app directly from GitHub.
My package.json looks like so:
{
"dependencies": {
"semantic-ui-react": "git+https://git#github.com/nolandg/Semantic-UI-React.git",
}
}
I then run
meteor npm install
Which appears to work fine and tells me it's installed the package:
semantic-ui-react#0.61.6 (git+https://git#github.com/nolandg/Semantic-UI-React.git#f27d5c736e5de1eed0acf7769f18caee57578526)
And indeed the package appears in the node_modules folder. But when I try to start my Meteor app, I get this error:
Cannot set property '/my-website/node_modules/semantic-ui-react/package.json' of undefined
at Resolver._resolvePkgJsonMain (/tools/isobuild/resolver.js:320:9)
Has anyone successfully install an npm package in a Meteor app directly from GitHub? I can't figure this one out. Thanks!
Meteor version: 1.4.2.3
The main reason why the package does not work when fetching from git is because it is not configured to work that way. This is not a Meteor specific problem, but a problem that a JS developer may face sometimes.
For this particular case there are two problems:
The whitelist files field in package.json only contains src and dist folder. That means when you fetch it by npm almost all config files needed to build the code are gone.
Code for this package requies to be built in order to work with your code. This is done when the author publish it to npm, but you fetch it directly from github so this step is undone.
Because you already folked and modified the package, so let modify the package.json as below (remove all the comments I added them to give you some explanation), push it to github, and fetch it again by npm:
// remove the "files" field
// ...
"scripts": {
// this script is used to build the package
"postinstall": "postinstall-build dist \"npm run build:commonjs\""
// ...
},
"dependencies": {
// this helps build the package
"postinstall-build": "^2.1.3"
},
// ...
Packages are not usually installed from github, they are published, which means that many versions of a package are available, you can choose which one you get. I'm not sure if what you are doing is possible, but it's certainly inadvisable.
If you want to make changes to a github package, you can download the it to your local machine and do npm link, so that it uses your local package instead of the one on npm. Read more about it at https://docs.npmjs.com/cli/link
Why do you not use simple command?
meteor npm install https://github.com/nolandg/Semantic-UI-React.git
I did:
meteor create test
cd test
meteor npm install
meteor add react react-dom
meteor npm install https://github.com/nolandg/Semantic-UI-React.git
meteor
And no errors (-:

Checking constraints for a Meteor package

In order to customize a third-party Meteor package, I copied the package folder from /Users/<name>/.meteor/packages/accounts-ui-unstyled/.1.1.8.cfkrwq++os+web.browser+web.cordova/ and pasted it into the packages folder at the root of my app as accounts-ui-unstyled/.
Now when the app compiles, I get this error:
Errors prevented startup:
While selecting package versions:
error: No version of accounts-ui-unstyled satisfies all constraints: #=0.0.0, #=1.1.8
Constraints on package "accounts-ui-unstyled":
* accounts-ui-unstyled#=0.0.0 <- top level
* accounts-ui-unstyled#=1.1.8 <- top level
* accounts-ui-unstyled#1.1.8 <- accounts-ui 1.1.6
Your application has errors. Waiting for file change.
Where are these constraints being declared, and what do I need to change to get the accounts-ui-unstyled/ folder in the packages folder to be correctly identified?
Normally you would like to create a local copy of a package by cloning its repository from GitHub (provided the source is available), and not from your local file system (which holds pre-built versions of the packages).
Sometimes (as it is the case with the core Meteor packages), they are "hidden" in sub-directories of the repository.
A neat trick is to use SVN in order to quickly get a snapshot of that sub-directory:
$ mkdir packages && cd packages
$ svn export https://github.com/meteor/meteor/trunk/packages/accounts-ui-unstyled
If you want to pull from a specific branch, use
$ svn export https://github.com/meteor/meteor/branches/<branch_name>/packages/<package-name>
The constraints will be specified in the package.js file, as expected.
Note: MDG are planning to move the core packages into their own repository/repositories, so those instructions may not be valid for the core packages in the future.

Install R package from Atlassian Stash

I made an R package which is hosted on my employer's instance of Atlassian Stash. I have been telling other users to clone the repo and then use devtools::install("<path-to-repo>") to install the package.
How can I have users install the package without cloning the repository? Can I do this without hosting the code somewhere more accessible?
Using this solution as a starting point, I discovered that you can use devtools with a Stash ssh url:
devtools::install_git("ssh://git#stash.yourdomain.com:1234/project/repo.git")
That will install from the latest commit on the master branch. You can also install a specific branch:
devtools::install_git("ssh://git#stash.yourdomain.com:1234/project/repo.git", branch="develop")
or tag:
devtools::install_git("ssh://git#stash.yourdomain.com:1234/project/repo.git", branch="v1.0")
(note you don't need the tags/ prefix when using a tag)
This will only work if you have SSH keys for your machine on your Stash account. Using the http clone url will not work, because you can't authenticate properly.

Resources