Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

chore(npm): Make modules Browserify compatible #10732

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions scripts/bower/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,37 @@ function prepare {
replaceJsonProp "bower.json" "angular.*" ".*" "$NEW_VERSION"
replaceJsonProp "package.json" "version" ".*" "$NEW_VERSION"
replaceJsonProp "package.json" "angular.*" ".*" "$NEW_VERSION"
deleteJsonProp "package.json" "main"

echo "-- Adding CommonJS index file"
echo "require('./$repo');" > index.js
echo "" >> index.js
if [ $repo == "angular" ]
then
echo "module.exports = angular;" >> index.js
else
# convert to module names (angular-animate >> ngAnimate)
suffix=`echo $repo | cut -c9-`
first=`echo $suffix | cut -c1 | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
tail=`echo $suffix | cut -c2-`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure to comment these lines clearly to indicate that you're transforming the repo name into a module name, alright?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, good idea.


if [ $repo != "angular-mocks" ]
then
echo "module.exports = 'ng$first$tail';" >> index.js
else
echo "exports.ngMock = 'ngMock';" >> index.js
echo "exports.ngMockE2E = 'ngMockE2E';" >> index.js
echo "exports.ngAnimateMock = 'ngAnimateMock';" >> index.js
fi

# add angular as a peer dependency
deleteJsonProp "package.json" "peerDependencies"
replaceInFile "package.json" "homepage\"\: \"http\:\/\/angularjs\.org\"$" "homepage\"\: \"http\:\/\/angularjs\.org\","
sed -i '' -e /^}/d "package.json"
# have to use single line form so deleteJsonProp will work
echo " \"peerDependencies\": { \"angular\": \"$NEW_VERSION\" }" >> package.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I highly recommend against using peerDependencies – npm/npm#5080 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I mention their problems and uncertain future, but @caitp pointed out that since these would be locked to a specific version we shouldn't have any issues. I'm happy to remove it, but that means devs will need to explicitly install angular itself, along with the other modules they need. (Which seems fine, just pointing out.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, no, I wrote a comment originally but removed it because of issues with npm that kind of get in the way of it =)

Basically, you need all the angular modules to be for the same version --- buuuuut, because npm does its own thing, every module can have its own versions of the same dependencies... so it doesn't really solve anything :(

peer deps don't really help either =\ it's just one of those things ._.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using peerDependencies like this would actually help, because if one were to npm i angular-route, you would get both angular and angular-route at the top level of your node_modules directory.

That being said, say the word and I will delete that line. :)

echo '}' >> package.json
fi

git add -A

Expand Down
6 changes: 6 additions & 0 deletions scripts/utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ function replaceJsonProp {
replaceInFile $1 '"('$2')"[ ]*:[ ]*"'$3'"' '"\1": "'$4'"'
}

# deleteJsonProp(jsonFile, property)
# - restriction: property needs to be on a single line!
function deleteJsonProp {
sed -i '' -e /\"$2\"\:/d $1
}

# replaceInFile(file, findPattern, replacePattern)
function replaceInFile {
sed -i .tmp -E "s/$2/$3/" $1
Expand Down