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 4 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
17 changes: 17 additions & 0 deletions scripts/bower/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ 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
echo "module.exports = $repo;" >> 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.


echo "module.exports = 'ng$first$tail';" >> index.js
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll give this a few other comments in the morning, but I guess ngMock is tricky, because it exports 3 different modules, and the module names don't end with an s like the repo name. Worry about that later though. Good work so far!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not making it in for 1.3.9, eh? :(

Thanks for all your help!

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